123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- const fs = require('fs');
- const path = require('path')
- const webpack = require('webpack')
- const createThemeColorReplacerPlugin = require('./config/plugin.config')
- const compressionWebpackPlugin = require('compression-webpack-plugin');
- const TerserPlugin = require('terser-webpack-plugin');
- const WebpackVersionPlugin = require('webpack-version-plugin');
- const versionConfig = require(resolve('public/version.json'));
- function resolve (dir) {
- return path.join(__dirname, dir)
- }
- function isProd () {
- return process.env.NODE_ENV === 'production'
- }
- const BASE_URL = isProd ? '/' : '/'
- const assetsCDN = {
- css: [],
-
- js: [
- BASE_URL + 'js/vue.min.js',
- BASE_URL + 'js/vue-router.min.js',
- BASE_URL + 'js/vuex.min.js',
- BASE_URL + 'js/axios.min.js',
- BASE_URL + 'js/echarts.min.js'
- ]
- }
- const prodExternals = {
- vue: 'Vue',
- 'vue-router': 'VueRouter',
- vuex: 'Vuex',
- axios: 'axios',
- echarts: 'echarts',
-
-
-
-
-
- 'mockjs2': 'Mock'
- }
- const vueConfig = {
- runtimeCompiler: true,
- publicPath: BASE_URL,
- configureWebpack: {
- optimization: isProd() ? {
- minimize: true,
- minimizer: [new TerserPlugin({
- test: /\.js(\?.*)?$/i,
- parallel: true,
- terserOptions: {
- output:{comments: false},
- compress: {
- pure_funcs: ["console.log"]
- }
- },
- extractComments: true,
- })],
- }:{},
-
- plugins: [
-
- new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
- new compressionWebpackPlugin({
-
- filename: '[path].gz[query]',
-
- algorithm: 'gzip',
-
- test: new RegExp('\\.(' + ['js', 'css'].join('|') + ')$'),
-
- threshold: 10240,
-
- minRatio: 0.8
- }),
- new WebpackVersionPlugin({
-
- cb: function(hashMap) {
- if(!isProd()){
- versionConfig.version = new Date().getTime();
- fs.writeFileSync(resolve('./public/version.json'), JSON.stringify(versionConfig, null, 2));
- }
- }
- })
- ],
-
- externals: isProd() ? prodExternals : {}
- },
- chainWebpack: (config) => {
- config.resolve.alias
- .set('@$', resolve('src'))
- const svgRule = config.module.rule('svg')
- svgRule.uses.clear()
- svgRule
- .oneOf('inline')
- .resourceQuery(/inline/)
- .use('vue-svg-icon-loader')
- .loader('vue-svg-icon-loader')
- .end()
- .end()
- .oneOf('external')
- .use('file-loader')
- .loader('file-loader')
- .options({
- name: 'assets/[name].[hash:8].[ext]'
- })
-
-
- if (isProd()) {
- config.plugin('html').tap(args => {
- args[0].cdn = assetsCDN
- return args
- })
- }
-
- config.optimization && config.optimization.splitChunks({
-
- chunks: 'all',
- minSize: 30000,
- maxSize: 0,
- minChunks: 1,
- maxAsyncRequests: 5,
- maxInitialRequests: 4,
- automaticNameDelimiter: '~',
- name: true,
- cacheGroups: {
-
- vendors: {
- test: /[\\/]node_modules[\\/]/,
- name: 'chunk-vendors',
-
-
-
-
- chunks: 'all',
- priority: -10,
- },
-
- antDesign: {
- name: 'chunk-antDesign',
- priority: 19,
- test: /[\\/]node_modules[\\/]_?@ant-design(.*)/
- },
- antDesignVue: {
- name: 'chunk-antDesignVue',
- priority: 20,
- test: /[\\/]node_modules[\\/]_?ant-design-vue(.*)/
- },
-
- common: {
- name: 'chunk-common',
- minChunks: 2,
- maxSize: 1024,
- priority: -20,
- reuseExistingChunk: true
- }
- }
- });
-
-
- if (process.env.npm_config_report) {
- config.plugin('webpack-bundle-analyzer')
- .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
- .end();
- }
- },
- css: {
- sourceMap: false,
- loaderOptions: {
- less: {
- modifyVars: {
-
- 'primary-color': process.env.VUE_APP_THEME_COLOR,
- 'link-color': process.env.VUE_APP_THEME_COLOR
-
- },
-
- javascriptEnabled: true
- }
- }
- },
- devServer: {
-
- port: 8000,
- disableHostCheck: true,
-
- proxy: {
- '/api': {
-
- target: 'http://p.iscm.360arrow.com/qpls-md',
-
- ws: true,
- changeOrigin: true,
- pathRewrite: {
- '^/api': ''
- }
- }
- },
- watchOptions: {
- ignored: [/node_modules/, /public/],
- }
- },
-
- productionSourceMap: false,
- assetsDir: 'static',
- lintOnSave: undefined,
-
- transpileDependencies: []
- }
- if (process.env.VUE_APP_PREVIEW === 'true') {
- console.log('VUE_APP_PREVIEW', true)
-
- vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
- }
- module.exports = vueConfig
|