-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from codebdy/feat/build
统一项目编译
- Loading branch information
Showing
88 changed files
with
7,895 additions
and
8,982 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './vite-config'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './src'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "@rxdrag/vite-config", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"type": "module", | ||
"module": "index.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist" | ||
}, | ||
"dependencies": { | ||
"vite": "^4.3.0" | ||
}, | ||
"devDependencies": { | ||
"@rxdrag/eslint-config-custom": "workspace:*", | ||
"@rxdrag/tsconfig": "workspace:*", | ||
"@types/fs-extra": "^11.0.1", | ||
"@vitejs/plugin-react": "^4.0.0", | ||
"antd": "^5.5.0", | ||
"dayjs": "^1.11.7", | ||
"dotenv": "^16.0.3", | ||
"fs-extra": "^11.1.1", | ||
"pkg-types": "^1.0.2", | ||
"rollup-plugin-visualizer": "^5.9.0", | ||
"vite-plugin-compression": "^0.5.1", | ||
"vite-plugin-dts": "^2.2.0", | ||
"vite-plugin-html": "^3.2.0", | ||
"vite-plugin-mock": "^2.9.6" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { resolve } from 'node:path'; | ||
|
||
import dayjs from 'dayjs'; | ||
import { readPackageJSON } from 'pkg-types'; | ||
import { defineConfig, loadEnv, mergeConfig, type UserConfig } from 'vite'; | ||
|
||
import { createPlugins } from '../plugins'; | ||
|
||
interface DefineOptions { | ||
overrides?: UserConfig; | ||
options?: { | ||
// | ||
}; | ||
} | ||
|
||
function defineApplicationConfig(defineOptions: DefineOptions = {}) { | ||
const { overrides = {} } = defineOptions; | ||
|
||
return defineConfig(async ({ command, mode }) => { | ||
const root = process.cwd(); | ||
const isBuild = command === 'build'; | ||
const { VITE_USE_MOCK, VITE_BUILD_COMPRESS, VITE_ENABLE_ANALYZE } = loadEnv(mode, root); | ||
|
||
const defineData = await createDefineData(root); | ||
const plugins = await createPlugins({ | ||
isBuild, | ||
root, | ||
enableAnalyze: VITE_ENABLE_ANALYZE === 'true', | ||
enableMock: VITE_USE_MOCK === 'true', | ||
compress: VITE_BUILD_COMPRESS, | ||
}); | ||
|
||
const pathResolve = (pathname: string) => resolve(root, '.', pathname); | ||
|
||
const applicationConfig: UserConfig = { | ||
resolve: { | ||
alias: [ | ||
// @/xxxx => src/xxxx | ||
{ | ||
find: /@\//, | ||
replacement: pathResolve('src') + '/', | ||
}, | ||
// #/xxxx => types/xxxx | ||
{ | ||
find: /#\//, | ||
replacement: pathResolve('types') + '/', | ||
}, | ||
], | ||
}, | ||
define: defineData, | ||
build: { | ||
target: 'es2017', | ||
cssTarget: 'chrome80', | ||
rollupOptions: { | ||
output: { | ||
manualChunks: { | ||
react: ['react', 'react-dom', 'react-router-dom'], | ||
antd: ['antd', '@ant-design/icons'], | ||
// libs: ['lodash', 'axios'], | ||
}, | ||
}, | ||
}, | ||
}, | ||
plugins, | ||
}; | ||
|
||
return mergeConfig(applicationConfig, overrides); | ||
}); | ||
} | ||
|
||
async function createDefineData(root: string) { | ||
try { | ||
const pkgJson = await readPackageJSON(root); | ||
const { dependencies, devDependencies, name, version } = pkgJson; | ||
|
||
const __APP_INFO__ = { | ||
pkg: { dependencies, devDependencies, name, version }, | ||
lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss'), | ||
}; | ||
return { | ||
__APP_INFO__: JSON.stringify(__APP_INFO__), | ||
}; | ||
} catch (error) { | ||
return {}; | ||
} | ||
} | ||
|
||
export { defineApplicationConfig }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { readPackageJSON } from 'pkg-types'; | ||
import { defineConfig, mergeConfig, type UserConfig } from 'vite'; | ||
import dts from 'vite-plugin-dts'; | ||
import { configVisualizerConfig } from '../plugins/visualizer'; | ||
|
||
interface DefineOptions { | ||
overrides?: UserConfig; | ||
options?: { | ||
// | ||
}; | ||
} | ||
|
||
function definePackageConfig(defineOptions: DefineOptions = {}) { | ||
const { overrides = {} } = defineOptions; | ||
const root = process.cwd(); | ||
return defineConfig(async () => { | ||
const { dependencies = {}, peerDependencies = {} } = await readPackageJSON( | ||
root | ||
); | ||
const packageConfig: UserConfig = { | ||
build: { | ||
sourcemap: true, | ||
minify: false, | ||
lib: { | ||
entry: 'src/index.ts', | ||
formats: ['es'], | ||
fileName: () => 'index.mjs' | ||
}, | ||
rollupOptions: { | ||
external: [ | ||
...Object.keys(dependencies), | ||
...Object.keys(peerDependencies) | ||
] | ||
} | ||
}, | ||
plugins: [ | ||
dts({ | ||
entryRoot: 'src', | ||
logLevel: 'error' | ||
}) | ||
// configVisualizerConfig(), | ||
] | ||
}; | ||
|
||
return mergeConfig(packageConfig, overrides); | ||
}); | ||
} | ||
|
||
export { definePackageConfig }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './config/application'; | ||
export * from './config/package'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { type PluginOption } from 'vite'; | ||
import react from '@vitejs/plugin-react'; | ||
|
||
import { configVisualizerConfig } from './visualizer'; | ||
|
||
interface Options { | ||
isBuild: boolean; | ||
root: string; | ||
compress: string; | ||
enableMock?: boolean; | ||
enableAnalyze?: boolean; | ||
} | ||
|
||
async function createPlugins({ isBuild, root, enableMock, compress, enableAnalyze }: Options) { | ||
const vitePlugins: (PluginOption | PluginOption[])[] = [react()]; | ||
|
||
if (enableAnalyze) { | ||
vitePlugins.push(configVisualizerConfig()); | ||
} | ||
return vitePlugins; | ||
} | ||
|
||
export { createPlugins }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { visualizer } from 'rollup-plugin-visualizer'; | ||
import { type PluginOption } from 'vite'; | ||
|
||
export function configVisualizerConfig() { | ||
return visualizer({ | ||
filename: './node_modules/.cache/visualizer/stats.html', | ||
open: true, | ||
gzipSize: true, | ||
brotliSize: true, | ||
}) as PluginOption; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extends": "@rxdrag/tsconfig/vite.json", | ||
"include": ["."], | ||
"exclude": ["dist", "build", "node_modules"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,44 @@ | ||
{ | ||
"name": "@rxdrag/fieldy-minions-activities", | ||
"version": "1.1.0", | ||
"main": "index.ts", | ||
"types": "./index.ts", | ||
"license": "MIT", | ||
"type": "module", | ||
"module": "index.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"publishConfig": { | ||
"module": "dist/index.mjs", | ||
"typings": "dist/index.d.ts", | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"lint": "eslint \"**/*.ts\"", | ||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist" | ||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist", | ||
"build": "vite build" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.0.28", | ||
"@types/react-dom": "^18.0.11", | ||
"antd": "^5.6.2", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"eslint": "^7.32.0", | ||
"@rxdrag/eslint-config-custom": "workspace:*", | ||
"@rxdrag/tsconfig": "workspace:*", | ||
"typescript": "^4.9.4" | ||
"@rxdrag/tsconfig": "workspace:*" | ||
}, | ||
"peerDependencies": { | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react-router-dom": "^6.8.1" | ||
"react-router-dom": "^6.8.1", | ||
"typescript": "^4.9.4" | ||
}, | ||
"dependencies": { | ||
"@types/react": "^18.0.28", | ||
"@types/react-dom": "^18.0.11", | ||
"@rxdrag/fieldy": "workspace:*", | ||
"@rxdrag/react-shared": "workspace:*", | ||
"@rxdrag/minions-runtime": "workspace:*", | ||
"@rxdrag/minions-schema": "workspace:*", | ||
"@rxdrag/schema": "workspace:*", | ||
"@rxdrag/shared": "workspace:*", | ||
"@rxdrag/fieldy-schema": "workspace:*", | ||
"antd": "^5.6.2", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
"@rxdrag/fieldy-schema": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { definePackageConfig } from '../../../internal'; | ||
|
||
export default definePackageConfig(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,41 @@ | ||
{ | ||
"name": "@rxdrag/fieldy-minions-materials", | ||
"version": "1.1.0", | ||
"main": "index.ts", | ||
"types": "./index.ts", | ||
"license": "MIT", | ||
"type": "module", | ||
"module": "index.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"publishConfig": { | ||
"module": "dist/index.mjs", | ||
"typings": "dist/index.d.ts", | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"lint": "eslint \"**/*.ts\"", | ||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist" | ||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist", | ||
"build": "vite build" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.0.28", | ||
"@types/react-dom": "^18.0.11", | ||
"eslint": "^7.32.0", | ||
"@rxdrag/eslint-config-custom": "workspace:*", | ||
"@rxdrag/tsconfig": "workspace:*", | ||
"typescript": "^4.9.4" | ||
"antd": "^5.6.2", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"eslint": "^7.32.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react-router-dom": "^6.8.1" | ||
}, | ||
"dependencies": { | ||
"@types/react": "^18.0.28", | ||
"@types/react-dom": "^18.0.11", | ||
"@rxdrag/schema": "workspace:*", | ||
"@rxdrag/shared": "workspace:*", | ||
"@rxdrag/fieldy-minions-activities": "workspace:*", | ||
"@rxdrag/minions-schema": "workspace:*", | ||
"@rxdrag/minions-runtime": "workspace:*", | ||
"antd": "^5.6.2", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
"@rxdrag/minions-runtime": "workspace:*" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { definePackageConfig } from '../../../internal'; | ||
|
||
export default definePackageConfig(); |
Oops, something went wrong.