Commit 49892048328a2f024772225c3fde2602d1bb9ae0
1 parent
4dcbcd48
1
Showing
2 changed files
with
164 additions
and
0 deletions
.DS_Store
No preview for this file type
wenjuan/vue.config.js
0 → 100644
| 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 Admin Template' // 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 methods: | |
| 15 | +// port = 9528 npm run dev OR npm run dev --port = 9528 | |
| 16 | +const port = process.env.port || process.env.npm_config_port || 9528 // 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 | + */ | |
| 27 | + runtimeCompiler: true, | |
| 28 | + publicPath: process.env.NODE_ENV === 'production' ? '/cdwlMall/' : '/', | |
| 29 | + // publicPath: '/admin-web', | |
| 30 | + outputDir: 'dist', | |
| 31 | + assetsDir: 'static', | |
| 32 | + lintOnSave: process.env.NODE_ENV === 'development', | |
| 33 | + productionSourceMap: false, | |
| 34 | + devServer: { | |
| 35 | + disableHostCheck:true, | |
| 36 | + port: port, | |
| 37 | + open: false, | |
| 38 | + overlay: { | |
| 39 | + warnings: false, | |
| 40 | + errors: true | |
| 41 | + }, | |
| 42 | + // before: require('./mock/mock-server.js'), | |
| 43 | + proxy: { | |
| 44 | + '/cdwlMall/meserver/api': { | |
| 45 | + target:process.env.VUE_APP_DOMAIN_PREFIX_2, | |
| 46 | + changeOrigin: true, | |
| 47 | + }, | |
| 48 | + '/cdwlMall/meserver/admin-server/':{ | |
| 49 | + target:process.env.VUE_APP_DOMAIN_PREFIX_1, | |
| 50 | + changeOrigin: true, | |
| 51 | + pathRewrite: { | |
| 52 | + // pathRewrite 方法重写 url | |
| 53 | + '^/meserver': '/', | |
| 54 | + }, | |
| 55 | + }, | |
| 56 | + } | |
| 57 | + }, | |
| 58 | + configureWebpack: { | |
| 59 | + // provide the app's title in webpack's name field, so that | |
| 60 | + // it can be accessed in index.html to inject the correct title. | |
| 61 | + name: name, | |
| 62 | + resolve: { | |
| 63 | + alias: { | |
| 64 | + '@': resolve('src'), | |
| 65 | + '@@': resolve('canvas-container') | |
| 66 | + } | |
| 67 | + } | |
| 68 | + }, | |
| 69 | + // 配置全局样式变量 | |
| 70 | + css: { | |
| 71 | + loaderOptions: { | |
| 72 | + sass: { | |
| 73 | + prependData: `@import "canvas-container/styles/index.scss";` | |
| 74 | + } | |
| 75 | + } | |
| 76 | + }, | |
| 77 | + // 配置多页面入口 | |
| 78 | + pages: { | |
| 79 | + index: { | |
| 80 | + entry: 'src/main.js', | |
| 81 | + template: 'public/index.html', | |
| 82 | + filename: 'index.html', | |
| 83 | + chunks: ['chunk-elementUI', 'chunk-vendors', 'chunk-libs', 'runtime', 'index'] | |
| 84 | + }, | |
| 85 | + canvas: { | |
| 86 | + entry: 'canvas-container/main.js', | |
| 87 | + template: 'public/canvas.html', | |
| 88 | + filename: 'canvas.html', | |
| 89 | + chunks: ['chunk-elementUI', 'chunk-vendors', 'chunk-libs', 'runtime', 'canvas'] | |
| 90 | + } | |
| 91 | + }, | |
| 92 | + chainWebpack(config) { | |
| 93 | + // it can improve the speed of the first screen, it is recommended to turn on preload | |
| 94 | + // config.plugin('preload').tap(() => [ | |
| 95 | + // { | |
| 96 | + // rel: 'preload', | |
| 97 | + // // to ignore runtime.js | |
| 98 | + // // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171 | |
| 99 | + // fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/], | |
| 100 | + // include: 'initial' | |
| 101 | + // } | |
| 102 | + // ]) | |
| 103 | + | |
| 104 | + // when there are many pages, it will cause too many meaningless requests | |
| 105 | + config.plugins.delete('prefetch') | |
| 106 | + | |
| 107 | + // set svg-sprite-loader | |
| 108 | + config.module | |
| 109 | + .rule('svg') | |
| 110 | + .exclude.add(resolve('src/icons')) | |
| 111 | + .end() | |
| 112 | + config.module | |
| 113 | + .rule('icons') | |
| 114 | + .test(/\.svg$/) | |
| 115 | + .include.add(resolve('src/icons')) | |
| 116 | + .end() | |
| 117 | + .use('svg-sprite-loader') | |
| 118 | + .loader('svg-sprite-loader') | |
| 119 | + .options({ | |
| 120 | + symbolId: 'icon-[name]' | |
| 121 | + }) | |
| 122 | + .end() | |
| 123 | + | |
| 124 | + config | |
| 125 | + .when(process.env.NODE_ENV !== 'development', | |
| 126 | + config => { | |
| 127 | + config | |
| 128 | + .plugin('ScriptExtHtmlWebpackPlugin') | |
| 129 | + .after('html') | |
| 130 | + .use('script-ext-html-webpack-plugin', [{ | |
| 131 | + // `runtime` must same as runtimeChunk name. default is `runtime` | |
| 132 | + inline: /runtime\..*\.js$/ | |
| 133 | + }]) | |
| 134 | + .end() | |
| 135 | + config | |
| 136 | + .optimization.splitChunks({ | |
| 137 | + chunks: 'all', | |
| 138 | + cacheGroups: { | |
| 139 | + libs: { | |
| 140 | + name: 'chunk-libs', | |
| 141 | + test: /[\\/]node_modules[\\/]/, | |
| 142 | + priority: 10, | |
| 143 | + chunks: 'initial' // only package third parties that are initially dependent | |
| 144 | + }, | |
| 145 | + elementUI: { | |
| 146 | + name: 'chunk-elementUI', // split elementUI into a single package | |
| 147 | + priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app | |
| 148 | + test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm | |
| 149 | + }, | |
| 150 | + commons: { | |
| 151 | + name: 'chunk-commons', | |
| 152 | + test: resolve('src/components'), // can customize your rules | |
| 153 | + minChunks: 3, // minimum common number | |
| 154 | + priority: 5, | |
| 155 | + reuseExistingChunk: true | |
| 156 | + } | |
| 157 | + } | |
| 158 | + }) | |
| 159 | + // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk | |
| 160 | + config.optimization.runtimeChunk('single') | |
| 161 | + } | |
| 162 | + ) | |
| 163 | + } | |
| 164 | +} | ... | ... |