dev 模式不加载 mini-css-extract-plugin,需先判断插件是否存在再调用 tap() Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
56 lines
1.7 KiB
JavaScript
56 lines
1.7 KiB
JavaScript
const path = require('path')
|
||
const AutoImport = require('unplugin-auto-import/webpack')
|
||
const Components = require('unplugin-vue-components/webpack')
|
||
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
|
||
const { defineConfig } = require('@vue/cli-service')
|
||
const { DefinePlugin } = require('webpack')
|
||
const { execSync } = require('child_process')
|
||
|
||
const commitInfo = execSync('git show -s --format=%cs(%h)').toString().trim()
|
||
|
||
module.exports = defineConfig({
|
||
publicPath: './',
|
||
transpileDependencies: true,
|
||
productionSourceMap: false,
|
||
configureWebpack: {
|
||
resolve: {
|
||
alias: { '@': path.resolve(__dirname, './src') }
|
||
},
|
||
plugins: [
|
||
AutoImport({
|
||
resolvers: [ElementPlusResolver()],
|
||
}),
|
||
Components({
|
||
resolvers: [ElementPlusResolver()],
|
||
}),
|
||
new DefinePlugin({
|
||
'process.env.VERSION': `'${commitInfo}'`
|
||
})
|
||
]
|
||
},
|
||
chainWebpack: config => {
|
||
// fork-ts-checker-webpack-plugin v6 与 TypeScript 5 不兼容(无法覆写只读的 performance.mark)
|
||
// 类型检查改由 tsc --noEmit 承担
|
||
config.plugins.delete('fork-ts-checker')
|
||
|
||
// Element Plus 按需导入时,不同路由 chunk 的 CSS 导入顺序不一致,
|
||
// 但这不影响最终样式(specificity 规则优先),忽略该警告
|
||
// extract-css 仅在生产构建时存在,dev 模式下跳过
|
||
if (config.plugins.has('extract-css')) {
|
||
config.plugin('extract-css').tap(args => {
|
||
args[0].ignoreOrder = true
|
||
return args
|
||
})
|
||
}
|
||
},
|
||
devServer: {
|
||
port: 8080,
|
||
proxy: {
|
||
'^/api': {
|
||
target: process.env.VUE_APP_PROXY_TARGET,
|
||
changeOrigin: true
|
||
}
|
||
}
|
||
}
|
||
})
|