'use strict';
const path = require('path');
const resolve = (dir) => path.resolve(__dirname, dir);
const isProduction = process.env.NODE_ENV !== 'development';
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const cdn = {
externals: {
vue: 'Vue',
vuex: 'Vuex',
'vue-router': 'VueRouter',
axios: 'axios',
},
js: [
'https://cdn.bootcss.com/vue/2.6.11/vue.runtime.min.js',
'https://cdn.bootcss.com/vue-router/3.1.2/vue-router.min.js',
'https://cdn.bootcss.com/vuex/3.1.2/vuex.min.js',
'https://cdn.bootcss.com/axios/0.19.2/axios.min.js',
'https://cdn.bootcss.com/moment.js/2.24.0/moment.min.js',
'https://cdn.bootcss.com/echarts/4.6.0/echarts.min.js',
],
css: [],
};
module.exports = {
publicPath: '/',
outputDir: 'dist',
assetsDir: 'static',
indexPath: 'index.html',
productionSourceMap: false,
chainWebpack: (config) => {
config.module
.rule('swf')
.test(/\.swf$/)
.use('url-loader')
.loader('url-loader')
.tap((options) => {
return {
limit: 10000,
};
});
config.resolve.alias
.set('@', resolve('src'))
.set('assets', resolve('src/assets'))
.set('components', resolve('src/components'))
.set('router', resolve('src/router'))
.set('store', resolve('src/store'))
.set('views', resolve('src/views'));
config.plugin('copy').tap((args) => {
args[0][0].to = 'resource';
return args;
});
config.plugins.delete('prefetch-index');
config.plugins.delete('preload-index');
config.plugin('html').tap((args) => {
args[0].cdn = cdn;
return args;
});
},
configureWebpack: (config) => {
config.externals = cdn.externals;
if (isProduction) {
const productionGzipExtensions = ['html', 'js', 'css'];
config.plugins.push(
new CompressionWebpackPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
threshold: 10240,
minRatio: 0.8,
deleteOriginalAssets: false,
})
);
config.optimization = {
splitChunks: {
cacheGroups: {
common: {
chunks: 'initial',
minSize: 0,
minChunks: 2,
},
vendor: {
priority: 1,
test: /node_modules/,
chunks: 'initial',
minSize: 0,
minChunks: 2,
},
},
},
};
}
},
devServer: {
overlay: {
warnings: false,
errors: false,
},
open: true,
host: '0.0.0.0',
port: 8081,
https: false,
hotOnly: true,
proxy: {
'/api': {
target: process.env.VUE_APP_API,
changeOrigin: true,
secure: false,
pathRewrite: {
'^/api': '/api/ctrl',
},
},
},
},
css: {
extract: true,
sourceMap: false,
loaderOptions: {
sass: {
prependData: `@import "~@/assets/scss/variables.scss";`,
},
},
},
};