const webpack = require('webpack');
|
const path = require('path');
|
|
const CompressionWebpackPlugin = require('compression-webpack-plugin');
|
const defaultSettings = require('./src/settings.js');
|
const port = process.env.port || process.env.npm_config_port || 9527; // dev port
|
function resolve (dir) {
|
return path.join(__dirname, dir);
|
}
|
const isProd = process.env.NODE_ENV === 'production';
|
const name = defaultSettings.title || '智能化立体库管理系统'; // page title
|
const {
|
VueCDN,
|
AxiosCDN,
|
VueRouterCDN,
|
VuexCDN
|
} = require('./src/plugins/cdn');
|
|
const cdn = {
|
css: [],
|
js: [VueCDN, AxiosCDN, VueRouterCDN, VuexCDN],
|
externals: {
|
vue: 'Vue',
|
'vue-router': 'VueRouter',
|
vuex: 'Vuex',
|
axios: 'axios'
|
}
|
};
|
module.exports = {
|
/**
|
*查看配置 https://cli.vuejs.org/config/#publicpath
|
*/
|
publicPath: '/', //根路径 cli3.0以上使用publicPath
|
//打包后输出路径
|
outputDir: 'dist',
|
assetsDir: 'static',
|
lintOnSave: false,
|
//去除生产环境的productionSourceMap
|
productionSourceMap: false,
|
devServer: {
|
port: port,
|
open: true,
|
overlay: {
|
warnings: false,
|
errors: true
|
},
|
proxy: {
|
[process.env.VUE_APP_BASE_API]: {
|
//target: 'http://10.103.11.236:8085', // 内网服务器部署 11网段
|
//target: 'http://10.103.9.200:8085/', // 内网服务器部署 9网段
|
//target: 'http://120.53.244.200:8085', // 云服务器测试
|
//target: 'http://192.168.43.252:8085', // 本机发布测试
|
//target: 'http://localhost:12319/', // 本机调试测试
|
//target: 'http://10.103.11.130:8085/', //11网段
|
target: 'http://localhost:6099/', //9网段
|
changeOrigin: true,
|
pathRewrite:{
|
'[process.env.VUE_APP_BASE_API]': ''
|
}
|
}
|
}
|
},
|
css: {
|
loaderOptions: {
|
sass: {}
|
}
|
},
|
// configureWebpack 值为对象,会通过 webpack-merge 合并到最终的配置
|
configureWebpack: {
|
//在webpack的name字段中提供应用程序的标题,以便可以在index.html中访问它来注入正确的标题
|
name: name,
|
resolve: {
|
alias: {
|
'@': resolve('src')
|
}
|
},
|
|
externals: {}
|
},
|
|
chainWebpack (config) {
|
config.plugin('define').tap(args => {
|
//args[0]['process.env'].IMAGE_URL = "'http://120.53.244.200:8085/'"; //测试环境
|
// args[0]['process.env'].IMAGE_URL = "'http://localhost:8085/'"; //正式环境 11网段
|
args[0]['process.env'].IMAGE_URL = "'http://10.103.9.200:8085/'"; //正式环境 9网段
|
//args[0]['process.env'].IMAGE_URL = "'http://192.168.137.200:8085/'"; //本机发布测试
|
return args;
|
});
|
config.plugin('provide').use(webpack.ProvidePlugin, [{
|
$: 'jquery',
|
jquery: 'jquery',
|
jQuery: 'jquery',
|
'window.jQuery': 'jquery'
|
}]);
|
// 设置svg
|
config.module.rule('svg').exclude.add(resolve('src/icons')).end();
|
config.module
|
.rule('icons')
|
.test(/\.svg$/)
|
.include.add(resolve('src/icons'))
|
.end()
|
.use('svg-sprite-loader')
|
.loader('svg-sprite-loader')
|
.options({
|
symbolId: 'icon-[name]'
|
})
|
.end();
|
//设置开发环境sourceMap
|
config.when(!isProd, config => config.devtool('cheap-source-map'));
|
//开发环境
|
|
config.when(isProd, config => {
|
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.plugin('html').tap(args => {
|
// args[0].cdn = cdn;
|
// return args;
|
// });
|
config.optimization.runtimeChunk('single');
|
|
//去除生产环境debugger 和console
|
config.optimization.minimizer('terser').tap(args => {
|
args[0].terserOptions.compress.warnings = false;
|
args[0].terserOptions.compress.drop_console = true;
|
args[0].terserOptions.compress.drop_debugger = true;
|
args[0].terserOptions.compress.pure_funcs = ['console.*'];
|
return args;
|
});
|
//g-zip开启
|
config.plugin('CompressionWebpackPlugin').use(CompressionWebpackPlugin, [{
|
filename: '[path].gz[query]',
|
algorithm: 'gzip',
|
test: /\.js$|\.css/, //匹配文件名
|
threshold: 10240, //对超过10k的数据压缩
|
minRatio: 0.8
|
}]);
|
});
|
}
|
};
|