Commit bd7b53f14adc05fd3d4af5027b5fb85015021ac9
1 parent
e6db0d39
fix(build): fix environment variable configuration file failure
Showing
19 changed files
with
167 additions
and
254 deletions
.env.development
.env.production
CHANGELOG.zh_CN.md
build/script/buildConf.ts
... | ... | @@ -4,7 +4,6 @@ |
4 | 4 | import { GLOB_CONFIG_FILE_NAME } from '../constant'; |
5 | 5 | import fs, { writeFileSync } from 'fs-extra'; |
6 | 6 | |
7 | -import viteConfig from '../../vite.config'; | |
8 | 7 | import { errorConsole, successConsole, getCwdPath, getEnvConfig } from '../utils'; |
9 | 8 | import { getShortName } from '../getShortName'; |
10 | 9 | |
... | ... | @@ -17,7 +16,7 @@ function createConfig( |
17 | 16 | ) { |
18 | 17 | try { |
19 | 18 | const windowConf = `window.${configName}`; |
20 | - const outDir = viteConfig.outDir || 'dist'; | |
19 | + const outDir = 'dist'; | |
21 | 20 | // Ensure that the variable will not be modified |
22 | 21 | const configStr = `${windowConf}=${JSON.stringify(config)}; |
23 | 22 | ... | ... |
build/script/postBuild.ts
1 | 1 | // #!/usr/bin/env node |
2 | 2 | |
3 | -import { sh } from 'tasksfile'; | |
4 | - | |
5 | 3 | import { argv } from 'yargs'; |
6 | 4 | import { runBuildConfig } from './buildConf'; |
7 | -// import { runUpdateHtml } from './updateHtml'; | |
8 | 5 | import { errorConsole, successConsole } from '../utils'; |
9 | 6 | import { startGzipStyle } from '../vite/plugin/gzip/compress'; |
10 | 7 | |
11 | -export const runBuild = async (preview = false) => { | |
8 | +export const runBuild = async () => { | |
12 | 9 | try { |
13 | 10 | const argvList = argv._; |
14 | - if (preview) { | |
15 | - let cmd = `cross-env NODE_ENV=production vite build`; | |
16 | - await sh(cmd, { | |
17 | - async: true, | |
18 | - nopipe: true, | |
19 | - }); | |
20 | - } | |
21 | 11 | |
22 | 12 | // Generate configuration file |
23 | 13 | if (!argvList.includes('no-conf')) { |
24 | 14 | await runBuildConfig(); |
25 | 15 | } |
26 | 16 | // await runUpdateHtml(); |
27 | - if (!preview) { | |
28 | - await startGzipStyle(); | |
29 | - } | |
17 | + await startGzipStyle(); | |
30 | 18 | successConsole('Vite Build successfully!'); |
31 | 19 | } catch (error) { |
32 | 20 | errorConsole('Vite Build Error\n' + error); | ... | ... |
build/script/preserve.ts deleted
100644 → 0
1 | -// Do you need to update the dependencies to prevent package.json from updating the dependencies, and no install after others get the code | |
2 | - | |
3 | -import path from 'path'; | |
4 | -import fs from 'fs-extra'; | |
5 | -import { isEqual } from 'lodash'; | |
6 | -import { sh } from 'tasksfile'; | |
7 | -import { successConsole, errorConsole } from '../utils'; | |
8 | - | |
9 | -const resolve = (dir: string) => { | |
10 | - return path.resolve(process.cwd(), dir); | |
11 | -}; | |
12 | - | |
13 | -const reg = /[\u4E00-\u9FA5\uF900-\uFA2D]/; | |
14 | - | |
15 | -let NEED_INSTALL = false; | |
16 | - | |
17 | -export async function runPreserve() { | |
18 | - // rc.6 fixed | |
19 | - const cwdPath = process.cwd(); | |
20 | - if (reg.test(cwdPath)) { | |
21 | - errorConsole( | |
22 | - 'Do not include Chinese, Japanese or Korean in the full path of the project directory, please modify the directory name and run again!' | |
23 | - ); | |
24 | - errorConsole('项目目录全路径请勿包含中文、日文、韩文,请修改目录名后再次重新运行!'); | |
25 | - process.exit(1); | |
26 | - } | |
27 | - | |
28 | - await fs.mkdirp(resolve('build/.cache')); | |
29 | - function checkPkgUpdate() { | |
30 | - const pkg = require('../../package.json'); | |
31 | - const { dependencies, devDependencies } = pkg; | |
32 | - const depsFile = resolve('build/.cache/deps.json'); | |
33 | - if (!fs.pathExistsSync(depsFile)) { | |
34 | - NEED_INSTALL = true; | |
35 | - return; | |
36 | - } | |
37 | - const depsJson = require('../.cache/deps.json'); | |
38 | - | |
39 | - if (!isEqual(depsJson, { dependencies, devDependencies })) { | |
40 | - NEED_INSTALL = true; | |
41 | - } | |
42 | - } | |
43 | - checkPkgUpdate(); | |
44 | - if (NEED_INSTALL) { | |
45 | - // no error | |
46 | - successConsole( | |
47 | - 'A dependency change is detected, and the dependency is being installed to ensure that the dependency is consistent! (Tip: The project will be executed for the first time)!' | |
48 | - ); | |
49 | - try { | |
50 | - await sh('npm run bootstrap ', { | |
51 | - async: true, | |
52 | - nopipe: true, | |
53 | - }); | |
54 | - | |
55 | - successConsole('Dependency installation is successful, start running the project!'); | |
56 | - | |
57 | - const pkg = require('../../package.json'); | |
58 | - const { dependencies, devDependencies } = pkg; | |
59 | - const depsFile = resolve('build/.cache/deps.json'); | |
60 | - const deps = { dependencies, devDependencies }; | |
61 | - if (!fs.pathExistsSync(depsFile)) { | |
62 | - fs.writeFileSync(depsFile, JSON.stringify(deps)); | |
63 | - } else { | |
64 | - const depsFile = resolve('build/.cache/deps.json'); | |
65 | - const depsJson = require('../.cache/deps.json'); | |
66 | - if (!isEqual(depsJson, deps)) { | |
67 | - fs.writeFileSync(depsFile, JSON.stringify(deps)); | |
68 | - } | |
69 | - } | |
70 | - } catch (error) {} | |
71 | - } | |
72 | -} | |
73 | - | |
74 | -runPreserve(); |
build/script/preview.ts
... | ... | @@ -4,12 +4,7 @@ import Koa from 'koa'; |
4 | 4 | import staticServer from 'koa-static'; |
5 | 5 | import portfinder from 'portfinder'; |
6 | 6 | import { resolve } from 'path'; |
7 | -import viteConfig from '../../vite.config'; | |
8 | 7 | import { getIPAddress } from '../utils'; |
9 | -// import { runBuild } from './postBuild'; | |
10 | - | |
11 | -// const BUILD = 1; | |
12 | -// const NO_BUILD = 2; | |
13 | 8 | |
14 | 9 | // start server |
15 | 10 | const startApp = () => { |
... | ... | @@ -17,7 +12,7 @@ const startApp = () => { |
17 | 12 | portfinder.basePort = port; |
18 | 13 | const app = new Koa(); |
19 | 14 | |
20 | - app.use(staticServer(resolve(process.cwd(), viteConfig.outDir || 'dist'))); | |
15 | + app.use(staticServer(resolve(process.cwd(), 'dist'))); | |
21 | 16 | |
22 | 17 | portfinder.getPort(async (err, port) => { |
23 | 18 | if (err) { |
... | ... | @@ -35,25 +30,4 @@ const startApp = () => { |
35 | 30 | }); |
36 | 31 | }; |
37 | 32 | |
38 | -// export const runPreview = async () => { | |
39 | -// // const prompt = inquirer.prompt({ | |
40 | -// // type: 'list', | |
41 | -// // message: 'Please select a preview method', | |
42 | -// // name: 'type', | |
43 | -// // choices: [ | |
44 | -// // { | |
45 | -// // name: 'Preview after packaging', | |
46 | -// // value: BUILD, | |
47 | -// // }, | |
48 | -// // { | |
49 | -// // name: `No packaging, preview directly (need to have dist file after packaging)`, | |
50 | -// // value: NO_BUILD, | |
51 | -// // }, | |
52 | -// // ], | |
53 | -// // }); | |
54 | -// const { type } = await prompt; | |
55 | -// if (type === BUILD) { | |
56 | -// await runBuild(true); | |
57 | -// } | |
58 | -// }; | |
59 | 33 | startApp(); | ... | ... |
build/utils.ts
... | ... | @@ -63,12 +63,12 @@ export function getIPAddress() { |
63 | 63 | return ''; |
64 | 64 | } |
65 | 65 | |
66 | -export function isDevFn(): boolean { | |
67 | - return process.env.NODE_ENV === 'development'; | |
66 | +export function isDevFn(mode: 'development' | 'production'): boolean { | |
67 | + return mode === 'development'; | |
68 | 68 | } |
69 | 69 | |
70 | -export function isProdFn(): boolean { | |
71 | - return process.env.NODE_ENV === 'production'; | |
70 | +export function isProdFn(mode: 'development' | 'production'): boolean { | |
71 | + return mode === 'production'; | |
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
... | ... | @@ -106,18 +106,11 @@ export interface ViteEnv { |
106 | 106 | } |
107 | 107 | |
108 | 108 | // Read all environment variable configuration files to process.env |
109 | -export function loadEnv(): ViteEnv { | |
110 | - const env = process.env.NODE_ENV; | |
109 | +export function wrapperEnv(envConf: any): ViteEnv { | |
111 | 110 | const ret: any = {}; |
112 | - const envList = [`.env.${env}.local`, `.env.${env}`, '.env.local', '.env', ,]; | |
113 | - envList.forEach((e) => { | |
114 | - dotenv.config({ | |
115 | - path: e, | |
116 | - }); | |
117 | - }); | |
118 | 111 | |
119 | - for (const envName of Object.keys(process.env)) { | |
120 | - let realName = (process.env as any)[envName].replace(/\\n/g, '\n'); | |
112 | + for (const envName of Object.keys(envConf)) { | |
113 | + let realName = envConf[envName].replace(/\\n/g, '\n'); | |
121 | 114 | realName = realName === 'true' ? true : realName === 'false' ? false : realName; |
122 | 115 | if (envName === 'VITE_PORT') { |
123 | 116 | realName = Number(realName); | ... | ... |
build/vite/plugin/gzip/compress.ts
1 | 1 | import { gzip } from 'zlib'; |
2 | 2 | import { readFileSync, writeFileSync } from 'fs'; |
3 | 3 | import { GzipPluginOptions } from './types'; |
4 | -import viteConfig from '../../../../vite.config'; | |
5 | 4 | import { readAllFile, getCwdPath, isBuildGzip, isSiteMode } from '../../../utils'; |
6 | 5 | |
7 | 6 | export function startGzip( |
... | ... | @@ -22,8 +21,8 @@ export function startGzip( |
22 | 21 | // 手动压缩css |
23 | 22 | export async function startGzipStyle() { |
24 | 23 | if (isBuildGzip() || isSiteMode()) { |
25 | - const outDir = viteConfig.outDir || 'dist'; | |
26 | - const assets = viteConfig.assetsDir || '_assets'; | |
24 | + const outDir = 'dist'; | |
25 | + const assets = '_assets'; | |
27 | 26 | const allCssFile = readAllFile(getCwdPath(outDir, assets), /\.(css)$/); |
28 | 27 | for (const path of allCssFile) { |
29 | 28 | const source = readFileSync(path); | ... | ... |
build/vite/plugin/html.ts
... | ... | @@ -7,16 +7,21 @@ import { hmScript } from '../hm'; |
7 | 7 | import pkg from '../../../package.json'; |
8 | 8 | import { GLOB_CONFIG_FILE_NAME } from '../../constant'; |
9 | 9 | |
10 | -export function setupHtmlPlugin(plugins: Plugin[], env: ViteEnv) { | |
10 | +export function setupHtmlPlugin( | |
11 | + plugins: Plugin[], | |
12 | + env: ViteEnv, | |
13 | + mode: 'development' | 'production' | |
14 | +) { | |
11 | 15 | const { VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH } = env; |
12 | 16 | |
13 | 17 | const htmlPlugin = ViteHtmlPlugin({ |
14 | 18 | // html title |
15 | 19 | title: VITE_GLOB_APP_TITLE, |
16 | - minify: isProdFn(), | |
20 | + minify: isProdFn(mode), | |
17 | 21 | options: { |
22 | + publicPath: VITE_PUBLIC_PATH, | |
18 | 23 | // Package and insert additional configuration files |
19 | - injectConfig: isProdFn() | |
24 | + injectConfig: isProdFn(mode) | |
20 | 25 | ? `<script src='${VITE_PUBLIC_PATH || './'}${GLOB_CONFIG_FILE_NAME}?v=${ |
21 | 26 | pkg.version |
22 | 27 | }-${new Date().getTime()}'></script>` | ... | ... |
build/vite/plugin/index.ts
... | ... | @@ -8,21 +8,21 @@ import gzipPlugin from './gzip/index'; |
8 | 8 | |
9 | 9 | // @ts-ignore |
10 | 10 | import pkg from '../../../package.json'; |
11 | -import { isProdFn, isSiteMode, ViteEnv, isReportMode, isBuildGzip } from '../../utils'; | |
11 | +import { isSiteMode, ViteEnv, isReportMode, isBuildGzip } from '../../utils'; | |
12 | 12 | import { setupHtmlPlugin } from './html'; |
13 | 13 | import { setupPwaPlugin } from './pwa'; |
14 | 14 | import { setupMockPlugin } from './mock'; |
15 | 15 | |
16 | 16 | // gen vite plugins |
17 | -export function createVitePlugins(viteEnv: ViteEnv) { | |
17 | +export function createVitePlugins(viteEnv: ViteEnv, mode: 'development' | 'production') { | |
18 | 18 | const vitePlugins: VitePlugin[] = []; |
19 | 19 | |
20 | 20 | // vite-plugin-html |
21 | - setupHtmlPlugin(vitePlugins, viteEnv); | |
21 | + setupHtmlPlugin(vitePlugins, viteEnv, mode); | |
22 | 22 | // vite-plugin-pwa |
23 | - setupPwaPlugin(vitePlugins, viteEnv); | |
23 | + setupPwaPlugin(vitePlugins, viteEnv, mode); | |
24 | 24 | // vite-plugin-mock |
25 | - setupMockPlugin(vitePlugins, viteEnv); | |
25 | + setupMockPlugin(vitePlugins, viteEnv, mode); | |
26 | 26 | |
27 | 27 | // vite-plugin-purge-icons |
28 | 28 | vitePlugins.push(PurgeIcons()); |
... | ... | @@ -34,12 +34,11 @@ export function createVitePlugins(viteEnv: ViteEnv) { |
34 | 34 | export function createRollupPlugin() { |
35 | 35 | const rollupPlugins: rollupPlugin[] = []; |
36 | 36 | |
37 | - if (!isProdFn() && isReportMode()) { | |
37 | + if (isReportMode()) { | |
38 | 38 | // rollup-plugin-visualizer |
39 | 39 | rollupPlugins.push(visualizer({ filename: './build/.cache/stats.html', open: true }) as Plugin); |
40 | 40 | } |
41 | - | |
42 | - if (!isProdFn() && (isBuildGzip() || isSiteMode())) { | |
41 | + if (isBuildGzip() || isSiteMode()) { | |
43 | 42 | // rollup-plugin-gizp |
44 | 43 | rollupPlugins.push(gzipPlugin()); |
45 | 44 | } | ... | ... |
build/vite/plugin/mock.ts
... | ... | @@ -2,14 +2,22 @@ import { createMockServer } from 'vite-plugin-mock'; |
2 | 2 | import type { Plugin } from 'vite'; |
3 | 3 | import { isDevFn, ViteEnv } from '../../utils'; |
4 | 4 | |
5 | -export function setupMockPlugin(plugins: Plugin[], env: ViteEnv) { | |
5 | +export function setupMockPlugin( | |
6 | + plugins: Plugin[], | |
7 | + env: ViteEnv, | |
8 | + mode: 'development' | 'production' | |
9 | +) { | |
6 | 10 | const { VITE_USE_MOCK } = env; |
7 | - const mockPlugin = createMockServer({ | |
8 | - ignore: /^\_/, | |
9 | - mockPath: 'mock', | |
10 | - showTime: true, | |
11 | - }); | |
12 | - if (isDevFn() && VITE_USE_MOCK) { | |
11 | + | |
12 | + const useMock = isDevFn(mode) && VITE_USE_MOCK; | |
13 | + | |
14 | + if (useMock) { | |
15 | + const mockPlugin = createMockServer({ | |
16 | + ignore: /^\_/, | |
17 | + mockPath: 'mock', | |
18 | + showTime: true, | |
19 | + localEnabled: useMock, | |
20 | + }); | |
13 | 21 | plugins.push(mockPlugin); |
14 | 22 | } |
15 | 23 | return plugins; | ... | ... |
build/vite/plugin/pwa.ts
1 | 1 | import { VitePWA } from 'vite-plugin-pwa'; |
2 | 2 | import type { Plugin } from 'vite'; |
3 | -import { isProdFn, ViteEnv } from '../../utils'; | |
3 | +import { ViteEnv } from '../../utils'; | |
4 | 4 | |
5 | -export function setupPwaPlugin(plugins: Plugin[], env: ViteEnv) { | |
5 | +export function setupPwaPlugin( | |
6 | + plugins: Plugin[], | |
7 | + env: ViteEnv, | |
8 | + // @ts-ignore | |
9 | + mode: 'development' | 'production' | |
10 | +) { | |
6 | 11 | const { VITE_USE_PWA } = env; |
7 | 12 | |
8 | 13 | const pwaPlugin = VitePWA({ |
... | ... | @@ -23,8 +28,7 @@ export function setupPwaPlugin(plugins: Plugin[], env: ViteEnv) { |
23 | 28 | ], |
24 | 29 | }, |
25 | 30 | }); |
26 | - | |
27 | - if (isProdFn() && VITE_USE_PWA) { | |
31 | + if (VITE_USE_PWA) { | |
28 | 32 | plugins.push(pwaPlugin); |
29 | 33 | } |
30 | 34 | return plugins; | ... | ... |
build/vite/proxy.ts
... | ... | @@ -2,21 +2,31 @@ type ProxyItem = [string, string]; |
2 | 2 | |
3 | 3 | type ProxyList = ProxyItem[]; |
4 | 4 | |
5 | -const reg = /^https:\/\//; | |
5 | +type ProxyTargetList = Record< | |
6 | + string, | |
7 | + { | |
8 | + target: string; | |
9 | + changeOrigin: boolean; | |
10 | + rewrite: (path: string) => any; | |
11 | + secure?: boolean; | |
12 | + } | |
13 | +>; | |
14 | + | |
15 | +const httpsRE = /^https:\/\//; | |
6 | 16 | |
7 | 17 | /** |
8 | 18 | * Generate proxy |
9 | 19 | * @param list |
10 | 20 | */ |
11 | 21 | export function createProxy(list: ProxyList = []) { |
12 | - const ret: any = {}; | |
22 | + const ret: ProxyTargetList = {}; | |
13 | 23 | for (const [prefix, target] of list) { |
14 | - const isHttps = reg.test(target); | |
24 | + const isHttps = httpsRE.test(target); | |
15 | 25 | |
16 | 26 | ret[prefix] = { |
17 | 27 | target: target, |
18 | 28 | changeOrigin: true, |
19 | - rewrite: (path: string) => path.replace(new RegExp(`^${prefix}`), ''), | |
29 | + rewrite: (path) => path.replace(new RegExp(`^${prefix}`), ''), | |
20 | 30 | // https is require secure=false |
21 | 31 | ...(isHttps ? { secure: false } : {}), |
22 | 32 | }; | ... | ... |
index.html
... | ... | @@ -137,7 +137,11 @@ |
137 | 137 | </style> |
138 | 138 | <div class="app-loading"> |
139 | 139 | <div class="app-loading-wrap"> |
140 | - <img src="./resource/img/logo.png" class="app-loading-logo" alt="Logo" /> | |
140 | + <img | |
141 | + src="<%= viteHtmlPluginOptions.publicPath %>resource/img/logo.png" | |
142 | + class="app-loading-logo" | |
143 | + alt="Logo" | |
144 | + /> | |
141 | 145 | <div class="app-loading-dots"> |
142 | 146 | <span class="dot dot-spin"><i></i><i></i><i></i><i></i></span> |
143 | 147 | </div> | ... | ... |
package.json
... | ... | @@ -3,8 +3,8 @@ |
3 | 3 | "version": "2.0.0-rc.14", |
4 | 4 | "scripts": { |
5 | 5 | "bootstrap": "yarn install", |
6 | - "serve": "esno ./build/script/preserve.ts && cross-env NODE_ENV=development vite", | |
7 | - "build": "cross-env NODE_ENV=production vite build && esno ./build/script/postBuild.ts", | |
6 | + "serve": "cross-env vite --mode=development", | |
7 | + "build": "cross-env vite build --mode=production && esno ./build/script/postBuild.ts", | |
8 | 8 | "build:site": "cross-env SITE=true npm run build ", |
9 | 9 | "build:no-cache": "yarn clean:cache && npm run build", |
10 | 10 | "typecheck": "typecheck .", | ... | ... |
src/main.ts
src/router/index.ts
... | ... | @@ -9,11 +9,9 @@ import { basicRoutes } from './routes/'; |
9 | 9 | import { scrollBehavior } from './scrollBehavior'; |
10 | 10 | import { REDIRECT_NAME } from './constant'; |
11 | 11 | |
12 | -export const hashRouter = createWebHashHistory(); | |
13 | - | |
14 | 12 | // app router |
15 | 13 | const router = createRouter({ |
16 | - history: hashRouter, | |
14 | + history: createWebHashHistory(), | |
17 | 15 | routes: basicRoutes as RouteRecordRaw[], |
18 | 16 | strict: true, |
19 | 17 | scrollBehavior: scrollBehavior, | ... | ... |
vite.config.ts
1 | 1 | import type { UserConfig, Resolver } from 'vite'; |
2 | 2 | import { resolve } from 'path'; |
3 | 3 | |
4 | +import { loadEnv } from 'vite'; | |
5 | + | |
4 | 6 | import { modifyVars } from './build/config/lessModifyVars'; |
5 | 7 | import { createProxy } from './build/vite/proxy'; |
6 | 8 | import { configManualChunk } from './build/vite/optimizer'; |
... | ... | @@ -8,16 +10,12 @@ import { configManualChunk } from './build/vite/optimizer'; |
8 | 10 | import globbyTransform from './build/vite/plugin/transform/globby'; |
9 | 11 | import dynamicImportTransform from './build/vite/plugin/transform/dynamic-import'; |
10 | 12 | |
11 | -import { loadEnv } from './build/utils'; | |
13 | +import { wrapperEnv } from './build/utils'; | |
12 | 14 | |
13 | 15 | import { createRollupPlugin, createVitePlugins } from './build/vite/plugin'; |
14 | 16 | |
15 | 17 | const pkg = require('./package.json'); |
16 | 18 | |
17 | -const viteEnv = loadEnv(); | |
18 | - | |
19 | -const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE, VITE_DYNAMIC_IMPORT } = viteEnv; | |
20 | - | |
21 | 19 | function pathResolve(dir: string) { |
22 | 20 | return resolve(__dirname, '.', dir); |
23 | 21 | } |
... | ... | @@ -30,84 +28,93 @@ const root: string = process.cwd(); |
30 | 28 | |
31 | 29 | const resolvers: Resolver[] = []; |
32 | 30 | |
33 | -const viteConfig: UserConfig = { | |
34 | - root, | |
35 | - alias, | |
36 | - /** | |
37 | - * port | |
38 | - * @default '3000' | |
39 | - */ | |
40 | - port: VITE_PORT, | |
41 | - | |
42 | - /** | |
43 | - * Base public path when served in production. | |
44 | - * @default '/' | |
45 | - */ | |
46 | - base: VITE_PUBLIC_PATH, | |
47 | - | |
48 | - /** | |
49 | - * Transpile target for esbuild. | |
50 | - * @default 'es2020' | |
51 | - */ | |
52 | - esbuildTarget: 'es2019', | |
53 | - | |
54 | - // terser options | |
55 | - terserOptions: { | |
56 | - compress: { | |
57 | - keep_infinity: true, | |
58 | - drop_console: VITE_DROP_CONSOLE, | |
31 | +export default (mode: 'development' | 'production'): UserConfig => { | |
32 | + const env = loadEnv(mode, root); | |
33 | + const viteEnv = wrapperEnv(env); | |
34 | + const { | |
35 | + VITE_PORT, | |
36 | + VITE_PUBLIC_PATH, | |
37 | + VITE_PROXY, | |
38 | + VITE_DROP_CONSOLE, | |
39 | + VITE_DYNAMIC_IMPORT, | |
40 | + } = viteEnv; | |
41 | + return { | |
42 | + root, | |
43 | + alias, | |
44 | + /** | |
45 | + * port | |
46 | + * @default '3000' | |
47 | + */ | |
48 | + port: VITE_PORT, | |
49 | + | |
50 | + /** | |
51 | + * Base public path when served in production. | |
52 | + * @default '/' | |
53 | + */ | |
54 | + base: VITE_PUBLIC_PATH, | |
55 | + | |
56 | + /** | |
57 | + * Transpile target for esbuild. | |
58 | + * @default 'es2020' | |
59 | + */ | |
60 | + esbuildTarget: 'es2019', | |
61 | + | |
62 | + // terser options | |
63 | + terserOptions: { | |
64 | + compress: { | |
65 | + keep_infinity: true, | |
66 | + drop_console: VITE_DROP_CONSOLE, | |
67 | + }, | |
68 | + }, | |
69 | + | |
70 | + define: { | |
71 | + __VERSION__: pkg.version, | |
72 | + // setting vue-i18-next | |
73 | + // Suppress warning | |
74 | + __VUE_I18N_LEGACY_API__: false, | |
75 | + __VUE_I18N_FULL_INSTALL__: false, | |
76 | + __INTLIFY_PROD_DEVTOOLS__: false, | |
77 | + }, | |
78 | + | |
79 | + cssPreprocessOptions: { | |
80 | + less: { | |
81 | + modifyVars: modifyVars, | |
82 | + javascriptEnabled: true, | |
83 | + }, | |
59 | 84 | }, |
60 | - }, | |
61 | - | |
62 | - define: { | |
63 | - __VERSION__: pkg.version, | |
64 | - // setting vue-i18-next | |
65 | - // Suppress warning | |
66 | - __VUE_I18N_LEGACY_API__: false, | |
67 | - __VUE_I18N_FULL_INSTALL__: false, | |
68 | - __INTLIFY_PROD_DEVTOOLS__: false, | |
69 | - }, | |
70 | - | |
71 | - cssPreprocessOptions: { | |
72 | - less: { | |
73 | - modifyVars: modifyVars, | |
74 | - javascriptEnabled: true, | |
85 | + | |
86 | + // The package will be recompiled using rollup, and the new package compiled into the esm module specification will be put into node_modules/.vite_opt_cache | |
87 | + optimizeDeps: { | |
88 | + include: [ | |
89 | + 'qs', | |
90 | + 'echarts/map/js/china', | |
91 | + 'ant-design-vue/es/locale/zh_CN', | |
92 | + 'ant-design-vue/es/locale/en_US', | |
93 | + '@ant-design/icons-vue', | |
94 | + ], | |
75 | 95 | }, |
76 | - }, | |
77 | - | |
78 | - // The package will be recompiled using rollup, and the new package compiled into the esm module specification will be put into node_modules/.vite_opt_cache | |
79 | - optimizeDeps: { | |
80 | - include: [ | |
81 | - 'qs', | |
82 | - 'echarts/map/js/china', | |
83 | - 'ant-design-vue/es/locale/zh_CN', | |
84 | - 'ant-design-vue/es/locale/en_US', | |
85 | - '@ant-design/icons-vue', | |
96 | + | |
97 | + transforms: [ | |
98 | + globbyTransform({ | |
99 | + resolvers: resolvers, | |
100 | + root: root, | |
101 | + alias: alias, | |
102 | + includes: [resolve('src/router'), resolve('src/locales')], | |
103 | + }), | |
104 | + dynamicImportTransform(VITE_DYNAMIC_IMPORT), | |
86 | 105 | ], |
87 | - }, | |
88 | - | |
89 | - transforms: [ | |
90 | - globbyTransform({ | |
91 | - resolvers: resolvers, | |
92 | - root: root, | |
93 | - alias: alias, | |
94 | - includes: [resolve('src/router'), resolve('src/locales')], | |
95 | - }), | |
96 | - dynamicImportTransform(VITE_DYNAMIC_IMPORT), | |
97 | - ], | |
98 | - | |
99 | - proxy: createProxy(VITE_PROXY), | |
100 | - | |
101 | - plugins: createVitePlugins(viteEnv), | |
102 | - | |
103 | - rollupInputOptions: { | |
104 | - plugins: createRollupPlugin(), | |
105 | - }, | |
106 | - | |
107 | - rollupOutputOptions: { | |
108 | - compact: true, | |
109 | - manualChunks: configManualChunk, | |
110 | - }, | |
111 | -}; | |
112 | 106 | |
113 | -export default viteConfig; | |
107 | + proxy: createProxy(VITE_PROXY), | |
108 | + | |
109 | + plugins: createVitePlugins(viteEnv, mode), | |
110 | + | |
111 | + rollupInputOptions: { | |
112 | + plugins: createRollupPlugin(), | |
113 | + }, | |
114 | + | |
115 | + rollupOutputOptions: { | |
116 | + compact: true, | |
117 | + manualChunks: configManualChunk, | |
118 | + }, | |
119 | + }; | |
120 | +}; | ... | ... |