|
@@ -1,30 +1,17 @@
|
|
|
'use strict'
|
|
|
const path = require('path')
|
|
|
const defaultSettings = require('./src/settings.js')
|
|
|
-const webpack = require('webpack');
|
|
|
+const webpack = require('webpack')
|
|
|
+const CompressionWebpackPlugin = require('compression-webpack-plugin')
|
|
|
|
|
|
function resolve(dir) {
|
|
|
return path.join(__dirname, dir)
|
|
|
}
|
|
|
|
|
|
const name = defaultSettings.title || 'vue Element Admin'
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
const port = process.env.port || process.env.npm_config_port || 9527
|
|
|
|
|
|
-
|
|
|
module.exports = {
|
|
|
-
|
|
|
- * You will need to set publicPath if you plan to deploy your site under a sub path,
|
|
|
- * for example GitHub Pages. If you plan to deploy your site to https:
|
|
|
- * then publicPath should be set to "/bar/".
|
|
|
- * In most cases please use '/' !!!
|
|
|
- * Detail: https:
|
|
|
- */
|
|
|
publicPath: '/',
|
|
|
outputDir: 'dist',
|
|
|
assetsDir: 'static',
|
|
@@ -37,58 +24,60 @@ module.exports = {
|
|
|
overlay: {
|
|
|
warnings: false,
|
|
|
errors: true
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
},
|
|
|
- configureWebpack: {
|
|
|
-
|
|
|
-
|
|
|
- name: name,
|
|
|
- resolve: {
|
|
|
- alias: {
|
|
|
- '@': resolve('src')
|
|
|
- }
|
|
|
- },
|
|
|
- plugins: [
|
|
|
+ configureWebpack: config => {
|
|
|
+ const plugins = [
|
|
|
new webpack.ProvidePlugin({
|
|
|
'window.Quill': 'quill/dist/quill.js',
|
|
|
- Quill: 'quill/dist/quill.js'
|
|
|
+ Quill: 'quill/dist/quill.js'
|
|
|
})
|
|
|
]
|
|
|
+
|
|
|
+ if (process.env.NODE_ENV === 'production') {
|
|
|
+ console.log('正在执行Gzip极限压缩!')
|
|
|
+
|
|
|
+ plugins.push(
|
|
|
+ new CompressionWebpackPlugin({
|
|
|
+ filename: '[path].gz[query]',
|
|
|
+ algorithm: 'gzip',
|
|
|
+ test: /\.(js|css|html|svg)$/,
|
|
|
+ threshold: 10240,
|
|
|
+ minRatio: 0.8
|
|
|
+ })
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ name: name,
|
|
|
+ resolve: {
|
|
|
+ alias: {
|
|
|
+ '@': resolve('src')
|
|
|
+ }
|
|
|
+ },
|
|
|
+ plugins
|
|
|
+ }
|
|
|
},
|
|
|
chainWebpack(config) {
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
config.plugin('preload').tap(() => [
|
|
|
{
|
|
|
rel: 'preload',
|
|
|
-
|
|
|
-
|
|
|
fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
|
|
|
include: 'initial'
|
|
|
}
|
|
|
])
|
|
|
|
|
|
-
|
|
|
+
|
|
|
config.plugins.delete('prefetch')
|
|
|
|
|
|
-
|
|
|
+
|
|
|
config.module
|
|
|
.rule('svg')
|
|
|
.exclude.add(resolve('src/icons'))
|
|
|
.end()
|
|
|
+
|
|
|
config.module
|
|
|
.rule('icons')
|
|
|
.test(/\.svg$/)
|
|
@@ -101,44 +90,39 @@ module.exports = {
|
|
|
})
|
|
|
.end()
|
|
|
|
|
|
- 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')
|
|
|
+ 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')
|
|
|
+ })
|
|
|
}
|
|
|
}
|