@@ -2,6 +2,7 @@ import path from "path"
22import type { ConfigEnv } from "vite"
33import { defineConfig , loadEnv } from "vite" // 帮手函数,这样不用 jsdoc 注解也可以获取类型提示
44import vue from "@vitejs/plugin-vue"
5+ import legacy from "@vitejs/plugin-legacy"
56import eslintPlugin from "vite-plugin-eslint"
67import { mars3dPlugin } from "vite-plugin-mars3d"
78import { createStyleImportPlugin , AndDesignVueResolve } from "vite-plugin-style-import"
@@ -18,14 +19,14 @@ export default ({ mode }: ConfigEnv) => {
1819 base : ENV . VITE_BASE_URL ,
1920 server : {
2021 host : "localhost" ,
21- https : false ,
2222 port : 3002
2323 } ,
2424 define : {
2525 "process.env" : {
2626 mode,
2727 BASE_URL : ENV . VITE_BASE_URL ,
28- API_BASE : ENV . VITE_API_URL
28+ API_BASE : ENV . VITE_API_URL ,
29+ API_LOCAL : ENV . VITE_LOCAL_API
2930 } ,
3031 buildTime : new Date ( )
3132 } ,
@@ -64,26 +65,62 @@ export default ({ mode }: ConfigEnv) => {
6465 commonjsOptions : {
6566 include : / n o d e _ m o d u l e s | p a c k a g e s /
6667 } ,
68+ // 静态资源目录
69+ assetsDir : "assets" ,
6770 // 自定义底层的 Rollup 打包配置
6871 rollupOptions : {
6972 input : {
7073 index : path . resolve ( __dirname , "index.html" ) ,
7174 demo : path . resolve ( __dirname , "demo.html" )
75+ } ,
76+ output : {
77+ chunkFileNames : "assets/js/[name]-[hash].js" ,
78+ entryFileNames : "assets/js/[name]-[hash].js" ,
79+ assetFileNames : "assets/[ext]/[name]-[hash].[ext]"
7280 }
7381 } ,
7482 // 当设置为 true, 构建后将会生成 manifest.json 文件
7583 manifest : false ,
7684 // 设置为 false 可以禁用最小化混淆,或是用来指定是应用哪种混淆器 boolean | 'terser' | 'esbuild'
7785 minify : "terser" ,
7886 // 传递给 Terser 的更多 minify 选项
79- terserOptions : { } ,
87+ terserOptions : {
88+ compress : {
89+ drop_console : true , // 在生产环境移除console.log
90+ drop_debugger : true // 在生产环境移除debugger
91+ }
92+ } ,
8093 // 设置为false 来禁用将构建好的文件写入磁盘
8194 write : true ,
8295 // 默认情况下 若 outDir 在 root 目录下, 则 Vite 会在构建时清空该目录。
8396 emptyOutDir : true
8497 } ,
8598 plugins : [
8699 vue ( ) ,
100+ // 兼容老版本浏览器配置
101+ // legacy({
102+ // targets: ["> 5%", "last 2 major versions", "chrome >80", "not dead"], // 需要兼容的目标列表,可以设置多个,参考.browserslistrc等
103+ // additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
104+ // renderLegacyChunks: true,
105+ // polyfills: [
106+ // "es.symbol",
107+ // "es.array.filter",
108+ // "es.promise",
109+ // "es.promise.finally",
110+ // "es/map",
111+ // "es/set",
112+ // "es.array.for-each",
113+ // "es.object.define-properties",
114+ // "es.object.define-property",
115+ // "es.object.get-own-property-descriptor",
116+ // "es.object.get-own-property-descriptors",
117+ // "es.object.keys",
118+ // "es.object.to-string",
119+ // "web.dom-collections.for-each",
120+ // "esnext.global-this",
121+ // "esnext.string.match-all"
122+ // ]
123+ // }),
87124 eslintPlugin ( { cache : false } ) ,
88125 mars3dPlugin ( { useStatic : false } ) ,
89126 createStyleImportPlugin ( {
0 commit comments