sijun.li | 9646230 | 2020-07-24 10:08:05 +0800 | [diff] [blame] | 1 | 'use strict' |
| 2 | const path = require('path') |
| 3 | const defaultSettings = require('./src/settings.js') |
| 4 | |
| 5 | function resolve(dir) { |
| 6 | return path.join(__dirname, dir) |
| 7 | } |
| 8 | |
| 9 | const name = defaultSettings.title || 'vue Element Admin' // page title |
| 10 | |
| 11 | // If your port is set to 80, |
| 12 | // use administrator privileges to execute the command line. |
| 13 | // For example, Mac: sudo npm run |
| 14 | // You can change the port by the following method: |
| 15 | // port = 9527 npm run dev OR npm run dev --port = 9527 |
| 16 | const port = process.env.port || process.env.npm_config_port || 9527 // dev port |
| 17 | |
| 18 | // All configuration item explanations can be find in https://cli.vuejs.org/config/ |
| 19 | module.exports = { |
| 20 | /** |
| 21 | * You will need to set publicPath if you plan to deploy your site under a sub path, |
| 22 | * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/, |
| 23 | * then publicPath should be set to "/bar/". |
| 24 | * In most cases please use '/' !!! |
| 25 | * Detail: https://cli.vuejs.org/config/#publicpath |
| 26 | */ |
sijun.li | 2c3a34f | 2020-08-17 15:18:32 +0800 | [diff] [blame] | 27 | publicPath: '/portal', |
sijun.li | 9646230 | 2020-07-24 10:08:05 +0800 | [diff] [blame] | 28 | outputDir: 'dist', |
| 29 | assetsDir: 'static', |
| 30 | lintOnSave: process.env.NODE_ENV === 'development', |
| 31 | productionSourceMap: false, |
| 32 | devServer: { |
| 33 | port: port, |
| 34 | open: true, |
| 35 | overlay: { |
| 36 | warnings: false, |
| 37 | errors: true |
| 38 | }, |
sijun.li | 2c3a34f | 2020-08-17 15:18:32 +0800 | [diff] [blame] | 39 | proxy: { |
| 40 | [process.env.VUE_APP_BASE_API]: { |
| 41 | target: process.env.VUE_APP_BASE_API, |
| 42 | changeOrigin: true, // 配置跨域 |
| 43 | pathRewrite: { |
| 44 | ['^' + process.env.VUE_APP_BASE_API]: '' |
| 45 | } |
| 46 | } |
| 47 | } |
sijun.li | 9646230 | 2020-07-24 10:08:05 +0800 | [diff] [blame] | 48 | }, |
| 49 | configureWebpack: { |
| 50 | // provide the app's title in webpack's name field, so that |
| 51 | // it can be accessed in index.html to inject the correct title. |
| 52 | name: name, |
| 53 | resolve: { |
| 54 | alias: { |
| 55 | '@': resolve('src') |
| 56 | } |
| 57 | } |
| 58 | }, |
| 59 | chainWebpack(config) { |
| 60 | // it can improve the speed of the first screen, it is recommended to turn on preload |
| 61 | // it can improve the speed of the first screen, it is recommended to turn on preload |
| 62 | config.plugin('preload').tap(() => [ |
| 63 | { |
| 64 | rel: 'preload', |
| 65 | // to ignore runtime.js |
| 66 | // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171 |
| 67 | fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/], |
| 68 | include: 'initial' |
| 69 | } |
| 70 | ]) |
| 71 | |
| 72 | // when there are many pages, it will cause too many meaningless requests |
| 73 | config.plugins.delete('prefetch') |
| 74 | |
| 75 | // set svg-sprite-loader |
| 76 | config.module |
| 77 | .rule('svg') |
| 78 | .exclude.add(resolve('src/icons')) |
| 79 | .end() |
| 80 | config.module |
| 81 | .rule('icons') |
| 82 | .test(/\.svg$/) |
| 83 | .include.add(resolve('src/icons')) |
| 84 | .end() |
| 85 | .use('svg-sprite-loader') |
| 86 | .loader('svg-sprite-loader') |
| 87 | .options({ |
| 88 | symbolId: 'icon-[name]' |
| 89 | }) |
| 90 | .end() |
| 91 | |
| 92 | config |
| 93 | .when(process.env.NODE_ENV !== 'development', |
| 94 | config => { |
| 95 | config |
| 96 | .plugin('ScriptExtHtmlWebpackPlugin') |
| 97 | .after('html') |
| 98 | .use('script-ext-html-webpack-plugin', [{ |
| 99 | // `runtime` must same as runtimeChunk name. default is `runtime` |
| 100 | inline: /runtime\..*\.js$/ |
| 101 | }]) |
| 102 | .end() |
| 103 | config |
| 104 | .optimization.splitChunks({ |
| 105 | chunks: 'all', |
| 106 | cacheGroups: { |
| 107 | libs: { |
| 108 | name: 'chunk-libs', |
| 109 | test: /[\\/]node_modules[\\/]/, |
| 110 | priority: 10, |
| 111 | chunks: 'initial' // only package third parties that are initially dependent |
| 112 | }, |
| 113 | elementUI: { |
| 114 | name: 'chunk-elementUI', // split elementUI into a single package |
| 115 | priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app |
| 116 | test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm |
| 117 | }, |
| 118 | commons: { |
| 119 | name: 'chunk-commons', |
| 120 | test: resolve('src/components'), // can customize your rules |
| 121 | minChunks: 3, // minimum common number |
| 122 | priority: 5, |
| 123 | reuseExistingChunk: true |
| 124 | } |
| 125 | } |
| 126 | }) |
| 127 | // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk |
| 128 | config.optimization.runtimeChunk('single') |
| 129 | } |
| 130 | ) |
| 131 | } |
| 132 | } |