|
@@ -44,43 +44,44 @@ module.exports = {
|
|
|
// 入口文件
|
|
|
config.entry.app = ["babel-polyfill", "./src/main.js"];
|
|
|
config.externals = {
|
|
|
- 'vue': 'Vue',
|
|
|
- axios: "axios",
|
|
|
- 'vue-router': 'VueRouter'
|
|
|
+ 'vue': 'Vue',
|
|
|
+ axios: "axios",
|
|
|
+ 'vue-router': 'VueRouter'
|
|
|
};
|
|
|
- if (isProduction) {
|
|
|
- config.plugins.push(new CompressionWebpackPlugin({
|
|
|
- algorithm: 'gzip',
|
|
|
- test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
|
|
|
- threshold: 10240,
|
|
|
- // deleteOriginalAssets:true, //删除源文件,不建议
|
|
|
- minRatio: 0.5
|
|
|
- }))
|
|
|
- }
|
|
|
+
|
|
|
// 删除console插件
|
|
|
let plugins = [
|
|
|
- new UglifyJsPlugin({
|
|
|
- uglifyOptions: {
|
|
|
- compress: {
|
|
|
- // warnings: false, // `warnings` is not a supported option
|
|
|
- drop_console: true,
|
|
|
- drop_debugger: true
|
|
|
- },
|
|
|
- output: {
|
|
|
- // 去掉注释内容
|
|
|
- comments: true
|
|
|
- }
|
|
|
- },
|
|
|
- cache: true, //启用/禁用文件缓存(类型可布尔也可是字符串)
|
|
|
- sourceMap: false,
|
|
|
- parallel: true
|
|
|
- })
|
|
|
+ new UglifyJsPlugin({
|
|
|
+ uglifyOptions: {
|
|
|
+ compress: {
|
|
|
+ // warnings: false, // `warnings` is not a supported option
|
|
|
+ drop_console: true,
|
|
|
+ drop_debugger: true
|
|
|
+ },
|
|
|
+ output: {
|
|
|
+ // 去掉注释内容
|
|
|
+ comments: true
|
|
|
+ }
|
|
|
+ },
|
|
|
+ cache: true, //启用/禁用文件缓存(类型可布尔也可是字符串)
|
|
|
+ sourceMap: false,
|
|
|
+ parallel: true
|
|
|
+ })
|
|
|
];
|
|
|
// 只有打包生产环境才需要将console删除
|
|
|
if (isProduction) {
|
|
|
- config.plugins = [...config.plugins, ...plugins];
|
|
|
+ config.plugins = [...config.plugins, ...plugins];
|
|
|
}
|
|
|
-},
|
|
|
+ if (isProduction) {
|
|
|
+ config.plugins.push(new CompressionWebpackPlugin({
|
|
|
+ algorithm: 'gzip',
|
|
|
+ test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
|
|
|
+ threshold: 10240,
|
|
|
+ // deleteOriginalAssets:true, //删除源文件,不建议
|
|
|
+ minRatio: 0.7
|
|
|
+ }))
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
chainWebpack(config) {
|
|
|
// it can improve the speed of the first screen, it is recommended to turn on preload
|
|
@@ -97,62 +98,83 @@ module.exports = {
|
|
|
|
|
|
// when there are many pages, it will cause too many meaningless requests
|
|
|
config.plugins.delete('prefetch')
|
|
|
+ // 解决ie11兼容ES6
|
|
|
+ config.entry('main').add('babel-polyfill')
|
|
|
+ // config.module.rule('images')
|
|
|
+ // .test(/\.(png|jpe?g|gif)(\?.*)?$/)
|
|
|
+ // .use('image-webpack-loader')
|
|
|
+ // .loader('image-webpack-loader')
|
|
|
+ // .options({ bypassOnDebug: true })
|
|
|
+
|
|
|
+ // 开启图片压缩
|
|
|
+ // config.module.rule('images')
|
|
|
+ // .test(/\.(png|jpe?g|gif)(\?.*)?$/)
|
|
|
+ // .use('url-loader')
|
|
|
+ // .loader('url-loader')
|
|
|
+ // .use('image-webpack-loader')
|
|
|
+ // .loader('image-webpack-loader')
|
|
|
+ // .options({ bypassOnDebug: true })
|
|
|
+ // 开启js、css压缩
|
|
|
|
|
|
- // set svg-sprite-loader
|
|
|
- config.module
|
|
|
- .rule('svg')
|
|
|
- .exclude.add(resolve('src/icons'))
|
|
|
- .end()
|
|
|
+
|
|
|
+ // set svg-sprite-loader
|
|
|
+ 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()
|
|
|
-//process.env.NODE_ENV !== 'development'
|
|
|
+ .rule('icons')
|
|
|
+ .test(/\.svg$/)
|
|
|
+ .include.add(resolve('src/icons'))
|
|
|
+ .end()
|
|
|
+ .use('svg-sprite-loader')
|
|
|
+ .loader('svg-sprite-loader')
|
|
|
+ .options({
|
|
|
+ symbolId: 'icon-[name]'
|
|
|
+ })
|
|
|
+ .end()
|
|
|
+ //process.env.NODE_ENV !== 'development'
|
|
|
config
|
|
|
.when(true,
|
|
|
- config => {
|
|
|
- config
|
|
|
- .plugin('ScriptExtHtmlWebpackPlugin')
|
|
|
- .after('html')
|
|
|
- .use('script-ext-html-webpack-plugin', [{
|
|
|
- // `runtime` must same as runtimeChunk name. default is `runtime`
|
|
|
- inline: /runtime\..*\.js$/
|
|
|
- }])
|
|
|
- .end()
|
|
|
- config
|
|
|
- .optimization.splitChunks({
|
|
|
- chunks: 'all',
|
|
|
- cacheGroups: {
|
|
|
- libs: {
|
|
|
- name: 'chunk-libs',
|
|
|
- test: /[\\/]node_modules[\\/]/,
|
|
|
- priority: 10,
|
|
|
- chunks: 'initial' // only package third parties that are initially dependent
|
|
|
- },
|
|
|
- // elementUI: {
|
|
|
- // name: 'chunk-elementUI', // split elementUI into a single package
|
|
|
- // priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
|
|
|
- // test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
|
|
|
- // },
|
|
|
- commons: {
|
|
|
- name: 'chunk-commons',
|
|
|
- test: resolve('src/components'), // can customize your rules
|
|
|
- minChunks: 3, // minimum common number
|
|
|
- priority: 5,
|
|
|
- reuseExistingChunk: true
|
|
|
- }
|
|
|
+ config => {
|
|
|
+ config
|
|
|
+ .plugin('ScriptExtHtmlWebpackPlugin')
|
|
|
+ .after('html')
|
|
|
+ .use('script-ext-html-webpack-plugin', [{
|
|
|
+ // `runtime` must same as runtimeChunk name. default is `runtime`
|
|
|
+ inline: /runtime\..*\.js$/
|
|
|
+ }])
|
|
|
+ .end()
|
|
|
+ config
|
|
|
+ .optimization.splitChunks({
|
|
|
+ chunks: 'all',
|
|
|
+ cacheGroups: {
|
|
|
+ libs: {
|
|
|
+ name: 'chunk-libs',
|
|
|
+ test: /[\\/]node_modules[\\/]/,
|
|
|
+ priority: 10,
|
|
|
+ chunks: 'initial' // only package third parties that are initially dependent
|
|
|
+ },
|
|
|
+ // elementUI: {
|
|
|
+ // name: 'chunk-elementUI', // split elementUI into a single package
|
|
|
+ // priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
|
|
|
+ // test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
|
|
|
+ // },
|
|
|
+ commons: {
|
|
|
+ name: 'chunk-commons',
|
|
|
+ test: resolve('src/components'), // can customize your rules
|
|
|
+ minChunks: 3, // minimum common number
|
|
|
+ priority: 5,
|
|
|
+ reuseExistingChunk: true
|
|
|
}
|
|
|
- })
|
|
|
- // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
|
|
|
- config.optimization.runtimeChunk('single')
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
|
|
|
+ config.optimization.runtimeChunk('single')
|
|
|
+ }
|
|
|
+ )
|
|
|
+},
|
|
|
+ transpileDependencies: [
|
|
|
+ 'biyi-admin', // 指定对第三方依赖包进行babel-polyfill处理
|
|
|
+ ]
|
|
|
}
|