Skip to content

Commit

Permalink
Merge pull request #146 from codebdy/feat/build
Browse files Browse the repository at this point in the history
统一项目编译
  • Loading branch information
codebdy authored Jul 3, 2023
2 parents c0e9739 + b42ec00 commit 269bfdf
Show file tree
Hide file tree
Showing 88 changed files with 7,895 additions and 8,982 deletions.
8 changes: 4 additions & 4 deletions apps/example-antd5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "example-antd5",
"private": true,
"version": "1.1.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
"build": "vite build",
"preview": "vite preview",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf build"
},
"dependencies": {
"@ant-design/icons": "^4.8.0",
Expand Down Expand Up @@ -50,4 +50,4 @@
"vite": "^4.2.0",
"vite-plugin-require-transform": "^1.0.9"
}
}
}
1 change: 1 addition & 0 deletions internal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './vite-config';
1 change: 1 addition & 0 deletions internal/vite-config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src';
32 changes: 32 additions & 0 deletions internal/vite-config/package.json
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"
}
}
88 changes: 88 additions & 0 deletions internal/vite-config/src/config/application.ts
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 };
49 changes: 49 additions & 0 deletions internal/vite-config/src/config/package.ts
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 };
2 changes: 2 additions & 0 deletions internal/vite-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './config/application';
export * from './config/package';
23 changes: 23 additions & 0 deletions internal/vite-config/src/plugins/index.ts
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 };
11 changes: 11 additions & 0 deletions internal/vite-config/src/plugins/visualizer.ts
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;
}
5 changes: 5 additions & 0 deletions internal/vite-config/tsconfig.json
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"]
}
32 changes: 19 additions & 13 deletions packages/fieldy-minions/activities/package.json
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:*"
}
}
3 changes: 3 additions & 0 deletions packages/fieldy-minions/activities/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { definePackageConfig } from '../../../internal';

export default definePackageConfig();
31 changes: 18 additions & 13 deletions packages/fieldy-minions/materials/package.json
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:*"
}
}
}
3 changes: 3 additions & 0 deletions packages/fieldy-minions/materials/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { definePackageConfig } from '../../../internal';

export default definePackageConfig();
Loading

0 comments on commit 269bfdf

Please sign in to comment.