Skip to content

Commit

Permalink
chore: 优化打包流程 加入条件编译
Browse files Browse the repository at this point in the history
  • Loading branch information
EricWXY committed May 27, 2024
1 parent 2a3b07d commit 6b700ab
Show file tree
Hide file tree
Showing 16 changed files with 210 additions and 8,512 deletions.
4 changes: 4 additions & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare const PROD: boolean;
declare const DEV: boolean;
declare const TEST: boolean;
declare const $message: any;
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
"dev": "pnpm --filter @eric-ui/playground dev",
"story": "pnpm --filter @eric-ui/playground storybook",
"docs:dev": "pnpm --filter @eric-ui/docs dev",
"docs:build": "pnpm --filter @eric-ui/docs build",
"test": "pnpm --filter @eric-ui/components test",
"build": "pnpm --filter eric-ui build"
"docs:build": "pnpm build && pnpm --filter @eric-ui/docs build",
"test": "cross-env NODE_ENV=test pnpm --filter @eric-ui/components test",
"build": "cross-env NODE_ENV=production pnpm --filter eric-ui build",
"build:dev": "cross-env NODE_ENV=development pnpm --filter eric-ui build:watch"
},
"keywords": [],
"author": "",
Expand All @@ -31,9 +32,11 @@
"devDependencies": {
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.11.20",
"@types/shelljs": "^0.8.15",
"@vitejs/plugin-vue": "^5.0.4",
"@vitejs/plugin-vue-jsx": "^3.1.0",
"@vue/tsconfig": "^0.5.1",
"cross-env": "^7.0.3",
"npm-run-all": "^4.1.5",
"postcss-color-mix": "^1.1.0",
"postcss-each": "^1.1.0",
Expand Down
9 changes: 5 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@
}
},
"scripts": {
"build": "run-s remove-dist build-only move-styles",
"build-only": "run-p build-es build-umd",
"build": "run-p build-es build-umd",
"build:watch": "run-p build-es:watch build-umd:watch",
"build-es": "vite build --config vite.es.config.ts",
"build-umd": "vite build --config vite.umd.config.ts",
"remove-dist": "node ./scripts/remove-dist.js",
"move-styles": "node ./scripts/move-styles.js"
"build-es:watch":"vite build --watch --config vite.es.config.ts",
"build-umd:watch": "vite build --watch --config vite.umd.config.ts"
},
"keywords": [],
"author": "EricWXY",
"license": "ISC",
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
"terser": "^5.31.0",
"vite-plugin-compression": "^0.5.1",
"vite-plugin-dts": "^3.9.1"
Expand Down
5 changes: 0 additions & 5 deletions packages/core/scripts/move-styles.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/core/scripts/remove-dist.js

This file was deleted.

47 changes: 32 additions & 15 deletions packages/core/vite.es.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import { readdirSync } from "fs";
import { filter, map } from "lodash-es";
import { delay, filter, map } from "lodash-es";
import shell from "shelljs";

import vue from "@vitejs/plugin-vue";
import dts from "vite-plugin-dts";
import compression from "vite-plugin-compression";
import terser from "@rollup/plugin-terser";

const isProd = process.env.NODE_ENV === "production";
const isDev = process.env.NODE_ENV === "development";
const isTest = process.env.NODE_ENV === "test";

const BUILD_END_DELAY = 2000 as const;

function getDirectoriesSync(basePath: string) {
const entries = readdirSync(basePath, { withFileTypes: true });
Expand All @@ -32,23 +39,36 @@ export default defineConfig({
outDir: "dist/es",
cssCodeSplit: true,
sourcemap: !isProd,
minify: "terser",
terserOptions: {
compress: {
drop_console: isProd,
drop_debugger: isProd,
keep_classnames: true,
keep_fnames: true,
evaluate: true,
},
},

lib: {
entry: resolve(__dirname, "./index.ts"),
name: "EricUI",
fileName: "index",
formats: ["es"],
},
rollupOptions: {
plugins: [
terser({
compress: {
drop_console: isProd,
drop_debugger: isProd,
global_defs: {
"@DEV": JSON.stringify(isDev),
"@PROD": JSON.stringify(isProd),
"@TEST": JSON.stringify(isTest),
},
},
}),
{
name: "customPlugin",
buildEnd(__, err?: Error) {
if (err) return;
delay(() => {
shell.mv("./dist/es/theme", "./dist");
}, BUILD_END_DELAY);
},
},
],
external: [
"vue",
"@fortawesome/fontawesome-svg-core",
Expand All @@ -57,9 +77,6 @@ export default defineConfig({
"@popperjs/core",
"async-validator",
],
input:{
'@eric-ui/components':'../components'
},
output: {
assetFileNames: (chunkInfo) => {
if (chunkInfo.name === "style.css") {
Expand Down
47 changes: 37 additions & 10 deletions packages/core/vite.umd.config.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,60 @@
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import shell from "shelljs";

import vue from "@vitejs/plugin-vue";
import compression from "vite-plugin-compression";
import terser from "@rollup/plugin-terser";
import { delay } from "lodash-es";

const isProd = process.env.NODE_ENV === "production";
const isDev = process.env.NODE_ENV === "development";
const isTest = process.env.NODE_ENV === "test";

const BUILD_END_DELAY = 8000 as const;

export default defineConfig({
plugins: [
vue(),
compression({
filter: /.(cjs|css)$/i
filter: /.(cjs|css)$/i,
}),
],
build: {
outDir: "dist/umd",
minify: "terser",
terserOptions: {
compress: {
drop_console: isProd,
drop_debugger: isProd,
evaluate: true,
},
},
lib: {
entry: resolve(__dirname, "./index.ts"),
name: "EricUI",
fileName: "index",
formats: ["umd"],
},
rollupOptions: {
plugins: [
terser({
compress: {
drop_console: isProd,
drop_debugger: isProd,
global_defs: {
"@DEV": JSON.stringify(isDev),
"@PROD": JSON.stringify(isProd),
"@TEST": JSON.stringify(isTest),
},
},
}),
{
name: "custromPlugin",
buildStart() {
isProd && shell.rm("-rf", "./dist");
},
buildEnd(__, err?: Error) {
if (err) return;
delay(() => {
shell.cp("./dist/umd/index.css", "./dist/index.css");
shell.cp("./dist/umd/index.css.gz", "./dist/index.css.gz");
}, BUILD_END_DELAY);
},
},
],
external: ["vue"],
output: {
exports: "named",
Expand Down
36 changes: 15 additions & 21 deletions packages/docs/.vitepress/cache/deps/_metadata.json
Original file line number Diff line number Diff line change
@@ -1,85 +1,79 @@
{
"hash": "469dce0b",
"hash": "012ac3aa",
"configHash": "b2ce0576",
"lockfileHash": "5f38e022",
"browserHash": "8c6b0a28",
"lockfileHash": "777c4d89",
"browserHash": "24288e09",
"optimized": {
"vue": {
"src": "../../../../../node_modules/.pnpm/vue@3.4.27_typescript@5.4.5/node_modules/vue/dist/vue.runtime.esm-bundler.js",
"file": "vue.js",
"fileHash": "6c6d8fac",
"fileHash": "f6ccdc1c",
"needsInterop": false
},
"vitepress > @vue/devtools-api": {
"src": "../../../../../node_modules/.pnpm/@vue+devtools-api@7.2.1_vue@3.4.27_typescript@5.4.5_/node_modules/@vue/devtools-api/dist/index.js",
"file": "vitepress___@vue_devtools-api.js",
"fileHash": "e789f2d3",
"fileHash": "394b8817",
"needsInterop": false
},
"vitepress > @vueuse/core": {
"src": "../../../../../node_modules/.pnpm/@vueuse+core@10.9.0_vue@3.4.27_typescript@5.4.5_/node_modules/@vueuse/core/index.mjs",
"file": "vitepress___@vueuse_core.js",
"fileHash": "e1c1b82b",
"fileHash": "caf53919",
"needsInterop": false
},
"vitepress > @vueuse/integrations/useFocusTrap": {
"src": "../../../../../node_modules/.pnpm/@vueuse+integrations@10.9.0_async-validator@4.2.5_axios@1.7.2_focus-trap@7.5.4_vue@3.4.27_typescript@5.4.5_/node_modules/@vueuse/integrations/useFocusTrap.mjs",
"file": "vitepress___@vueuse_integrations_useFocusTrap.js",
"fileHash": "5b7009c5",
"fileHash": "0fb23b8d",
"needsInterop": false
},
"vitepress > mark.js/src/vanilla.js": {
"src": "../../../../../node_modules/.pnpm/mark.js@8.11.1/node_modules/mark.js/src/vanilla.js",
"file": "vitepress___mark__js_src_vanilla__js.js",
"fileHash": "0da5ce99",
"fileHash": "d394b376",
"needsInterop": false
},
"vitepress > minisearch": {
"src": "../../../../../node_modules/.pnpm/minisearch@6.3.0/node_modules/minisearch/dist/es/index.js",
"file": "vitepress___minisearch.js",
"fileHash": "b9843f5d",
"fileHash": "15ebb205",
"needsInterop": false
},
"@vitepress-demo-preview/component": {
"src": "../../../../../node_modules/.pnpm/@vitepress-demo-preview+component@2.3.2_vitepress@1.0.0-rc.44_@algolia+client-search@4.23.3_@_apqwrhmwonoulis4wqubgz43e4/node_modules/@vitepress-demo-preview/component/dist/preview-component.js",
"file": "@vitepress-demo-preview_component.js",
"fileHash": "44cf8ea2",
"fileHash": "ba8aabe3",
"needsInterop": false
},
"@fortawesome/fontawesome-svg-core": {
"src": "../../../../../node_modules/.pnpm/@fortawesome+fontawesome-svg-core@6.5.2/node_modules/@fortawesome/fontawesome-svg-core/index.mjs",
"file": "@fortawesome_fontawesome-svg-core.js",
"fileHash": "ed34d7d7",
"fileHash": "e020eb5a",
"needsInterop": false
},
"@fortawesome/free-solid-svg-icons": {
"src": "../../../../../node_modules/.pnpm/@fortawesome+free-solid-svg-icons@6.5.2/node_modules/@fortawesome/free-solid-svg-icons/index.mjs",
"file": "@fortawesome_free-solid-svg-icons.js",
"fileHash": "82e1571c",
"fileHash": "7635beec",
"needsInterop": false
},
"@fortawesome/vue-fontawesome": {
"src": "../../../../../node_modules/.pnpm/@fortawesome+vue-fontawesome@3.0.8_@fortawesome+fontawesome-svg-core@6.5.2_vue@3.4.27_typescript@5.4.5_/node_modules/@fortawesome/vue-fontawesome/index.es.js",
"file": "@fortawesome_vue-fontawesome.js",
"fileHash": "4eeb1e42",
"fileHash": "582828c9",
"needsInterop": false
},
"@popperjs/core": {
"src": "../../../../../node_modules/.pnpm/@popperjs+core@2.11.8/node_modules/@popperjs/core/lib/index.js",
"file": "@popperjs_core.js",
"fileHash": "2141c90b",
"fileHash": "afef8190",
"needsInterop": false
},
"async-validator": {
"src": "../../../../../node_modules/.pnpm/async-validator@4.2.5/node_modules/async-validator/dist-web/index.js",
"file": "async-validator.js",
"fileHash": "1595c5b2",
"needsInterop": false
},
"lodash-es": {
"src": "../../../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/lodash.js",
"file": "lodash-es.js",
"fileHash": "132c6121",
"fileHash": "afc271f3",
"needsInterop": false
}
},
Expand Down
Loading

0 comments on commit 6b700ab

Please sign in to comment.