jazz
2022-08-24 a4b91616ceae752e11cb6fc5198ebadf52cd68ed
提交 | 用户 | age
2a61f6 1 'use strict'
L 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   publicPath: './',
28   outputDir: 'dist',
29   assetsDir: 'static',
30   lintOnSave: process.env.NODE_ENV === 'development',
31   productionSourceMap: false,
32   devServer: {
33     proxy: {
34       '/api_test': {
5dfa4a 35         // target: 'http://192.168.2.106:3602/sms', // - 其
b41339 36         target: 'https://sms.phiskin.com/sms-admin', // - 线上
2a61f6 37         // target: 'http://192.168.1.163:8080/',
L 38         // target: 'http://192.168.31.143:8080/', // 和
39         // target: 'http://192.168.31.143:8888/', // 和
40         changeOrigin: true,
41         ws: true,
42         pathRewrite: {
43           '^/api_test': ''
44         }
45       },
46       '/api_online': {
47         target: 'https://线上请求路径/',
48         changeOrigin: true,
49         ws: true,
50         pathRewrite: {
51           '^/api_online': ''
52         }
53       }
54     }
55   },
56   configureWebpack: {
57     // provide the app's title in webpack's name field, so that
58     // it can be accessed in index.html to inject the correct title.
59     name: name,
60     resolve: {
61       alias: {
62         '@': resolve('src')
63       }
64     }
65   },
66   chainWebpack(config) {
67     // it can improve the speed of the first screen, it is recommended to turn on preload
68     config.plugin('preload').tap(() => [
69       {
70         rel: 'preload',
71         // to ignore runtime.js
72         // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
73         fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
74         include: 'initial'
75       }
76     ])
77
78     // when there are many pages, it will cause too many meaningless requests
79     config.plugins.delete('prefetch')
80
bf9798 81     // 打包后注释console TODO 待测试
L 82     // config.optimization.minimizer('terser').tap((args) => { args[0].terserOptions.compress.drop_console = true; return args })
83
2a61f6 84     // set svg-sprite-loader
L 85     config.module
86       .rule('svg')
87       .exclude.add(resolve('src/icons'))
88       .end()
89     config.module
90       .rule('icons')
91       .test(/\.svg$/)
92       .include.add(resolve('src/icons'))
93       .end()
94       .use('svg-sprite-loader')
95       .loader('svg-sprite-loader')
96       .options({
97         symbolId: 'icon-[name]'
98       })
99       .end()
100
101     config
102       .when(process.env.NODE_ENV !== 'development',
103         config => {
104           config
105             .plugin('ScriptExtHtmlWebpackPlugin')
106             .after('html')
107             .use('script-ext-html-webpack-plugin', [{
108             // `runtime` must same as runtimeChunk name. default is `runtime`
109               inline: /runtime\..*\.js$/
110             }])
111             .end()
112           config
113             .optimization.splitChunks({
114               chunks: 'all',
115               cacheGroups: {
116                 libs: {
117                   name: 'chunk-libs',
118                   test: /[\\/]node_modules[\\/]/,
119                   priority: 10,
120                   chunks: 'initial' // only package third parties that are initially dependent
121                 },
122                 elementUI: {
123                   name: 'chunk-elementUI', // split elementUI into a single package
124                   priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
125                   test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
126                 },
127                 commons: {
128                   name: 'chunk-commons',
129                   test: resolve('src/components'), // can customize your rules
130                   minChunks: 3, //  minimum common number
131                   priority: 5,
132                   reuseExistingChunk: true
133                 }
134               }
135             })
136           // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
137           config.optimization.runtimeChunk('single')
138         }
139       )
140   }
141 }