加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
vue.config.js 3.03 KB
一键复制 编辑 原始数据 按行查看 历史
xLong1029 提交于 2022-05-09 15:33 . 修改组件上传
'use strict'
const webpack = require('webpack');
const production = process.env.NODE_ENV === 'production';
const path = require('path');
function resolve(dir) {
return path.join(__dirname, dir);
}
// 相关配置请参考 https://cli.vuejs.org/config/
module.exports = {
publicPath: production ? './' : '/',
outputDir: 'dist',
assetsDir: 'static',
lintOnSave: process.env.NODE_ENV === 'development',
productionSourceMap: false,
// 代理服务
devServer: {
port: 9090,
// open: true, //禁用后只打开1次页面
overlay: {
warnings: false,
errors: true
}
},
configureWebpack: {
resolve: {
// 定义别名和插件位置
alias: {
'@': resolve('src'),
'api': resolve('src/api'),
'mock': resolve('src/mock'),
'mixins': resolve('src/mixins'),
'assets': resolve('src/assets'),
'config': resolve('src/config'),
'components': resolve('src/components'),
'views': resolve('src/views'),
'utils': resolve('src/utils'),
'router': resolve('src/router'),
}
},
plugins: [
// new webpack.ProvidePlugin({
// $: 'jquery',
// jQuery: 'jquery',
// 'window.jQuery': 'jquery',
// 'root.jQuery': 'jquery'
// })
],
// 外部引用
externals: {
$: 'jquery'
}
},
chainWebpack(config) {
config.plugins.delete('preload')
config.plugins.delete('prefetch')
config.module
.rule('vue')
.use('vue-loader')
.loader('vue-loader')
.tap(options => {
options.compilerOptions.preserveWhitespace = true
return options
})
.end()
config
.when(process.env.NODE_ENV === 'development',
config => config.devtool('cheap-source-map')
)
config
.when(process.env.NODE_ENV !== 'development',
config => {
config
.plugin('ScriptExtHtmlWebpackPlugin')
.after('html')
.use('script-ext-html-webpack-plugin', [{
inline: /runtime\..*\.js$/
}])
.end()
config
.optimization.splitChunks({
chunks: 'all',
cacheGroups: {
libs: {
name: 'chunk-libs',
test: /[\\/]node_modules[\\/]/,
priority: 10,
chunks: 'initial'
},
elementUI: {
name: 'chunk-elementUI',
priority: 20,
test: /[\\/]node_modules[\\/]_?element-ui(.*)/
},
commons: {
name: 'chunk-commons',
test: resolve('src/components'),
minChunks: 3,
priority: 5,
reuseExistingChunk: true
}
}
})
config.optimization.runtimeChunk('single')
}
)
},
css: {
loaderOptions: {
sass: {
data: `
@import "@/styles/variables.scss";
`
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化