¶Ô±ÈÐÂÎļþ |
| | |
| | | 'use strict' |
| | | const path = require('path') |
| | | const defaultSettings = require('./src/settings.js') |
| | | |
| | | function resolve(dir) { |
| | | return path.join(__dirname, dir) |
| | | } |
| | | |
| | | const name = defaultSettings.title || 'è¥ä¾ç®¡çç³»ç»' // æ é¢ |
| | | |
| | | const port = process.env.port || process.env.npm_config_port || 80 // ç«¯å£ |
| | | |
| | | // vue.config.js é
置说æ |
| | | //宿¹vue.config.js åèææ¡£ https://cli.vuejs.org/zh/config/#css-loaderoptions |
| | | // è¿éåªåä¸é¨åï¼å
·ä½é
ç½®åèææ¡£ |
| | | module.exports = { |
| | | // é¨ç½²ç产ç¯å¢åå¼åç¯å¢ä¸çURLã |
| | | // é»è®¤æ
åµä¸ï¼Vue CLI ä¼åè®¾ä½ çåºç¨æ¯è¢«é¨ç½²å¨ä¸ä¸ªååçæ ¹è·¯å¾ä¸ |
| | | // ä¾å¦ https://www.ruoyi.vip/ã妿åºç¨è¢«é¨ç½²å¨ä¸ä¸ªåè·¯å¾ä¸ï¼ä½ å°±éè¦ç¨è¿ä¸ªé项æå®è¿ä¸ªåè·¯å¾ãä¾å¦ï¼å¦æä½ çåºç¨è¢«é¨ç½²å¨ https://www.ruoyi.vip/admin/ï¼å设置 baseUrl 为 /admin/ã |
| | | publicPath: process.env.NODE_ENV === "production" ? "/" : "/", |
| | | // å¨npm run build æ yarn build æ¶ ï¼çææä»¶çç®å½åç§°ï¼è¦åbaseUrlçç产ç¯å¢è·¯å¾ä¸è´ï¼ï¼é»è®¤distï¼ |
| | | outputDir: 'dist', |
| | | // ç¨äºæ¾ç½®çæçéæèµæº (jsãcssãimgãfonts) çï¼ï¼é¡¹ç®æå
ä¹åï¼éæèµæºä¼æ¾å¨è¿ä¸ªæä»¶å¤¹ä¸ï¼ |
| | | assetsDir: 'static', |
| | | // æ¯å¦å¼å¯eslintä¿åæ£æµï¼ææå¼ï¼ture | false | 'error' |
| | | lintOnSave: process.env.NODE_ENV === 'development', |
| | | // å¦æä½ ä¸éè¦ç产ç¯å¢ç source mapï¼å¯ä»¥å°å
¶è®¾ç½®ä¸º false 以å éç产ç¯å¢æå»ºã |
| | | productionSourceMap: false, |
| | | // webpack-dev-server ç¸å
³é
ç½® |
| | | devServer: { |
| | | host: '0.0.0.0', |
| | | port: port, |
| | | proxy: { |
| | | // detail: https://cli.vuejs.org/config/#devserver-proxy |
| | | [process.env.VUE_APP_BASE_API]: { |
| | | target: `http://localhost:8081`, |
| | | changeOrigin: true, |
| | | pathRewrite: { |
| | | ['^' + process.env.VUE_APP_BASE_API]: '' |
| | | } |
| | | } |
| | | }, |
| | | disableHostCheck: true |
| | | }, |
| | | configureWebpack: { |
| | | name: name, |
| | | resolve: { |
| | | alias: { |
| | | '@': resolve('src') |
| | | } |
| | | } |
| | | }, |
| | | chainWebpack(config) { |
| | | config.plugins.delete('preload') // TODO: need test |
| | | config.plugins.delete('prefetch') // TODO: need test |
| | | |
| | | // set svg-sprite-loader |
| | | config.module |
| | | .rule('svg') |
| | | .exclude.add(resolve('src/assets/icons')) |
| | | .end() |
| | | config.module |
| | | .rule('icons') |
| | | .test(/\.svg$/) |
| | | .include.add(resolve('src/assets/icons')) |
| | | .end() |
| | | .use('svg-sprite-loader') |
| | | .loader('svg-sprite-loader') |
| | | .options({ |
| | | symbolId: 'icon-[name]' |
| | | }) |
| | | .end() |
| | | |
| | | // set preserveWhitespace |
| | | config.module |
| | | .rule('vue') |
| | | .use('vue-loader') |
| | | .loader('vue-loader') |
| | | .tap(options => { |
| | | options.compilerOptions.preserveWhitespace = true |
| | | return options |
| | | }) |
| | | .end() |
| | | |
| | | config |
| | | .when(process.env.NODE_ENV !== 'development', |
| | | 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.optimization.runtimeChunk('single'), |
| | | { |
| | | from: path.resolve(__dirname, './public/robots.txt'),//é²ç¬è«æä»¶ |
| | | to:'./',//å°æ ¹ç®å½ä¸ |
| | | } |
| | | } |
| | | ) |
| | | } |
| | | } |