'use strict' const path = require('path') function resolve(dir) { return path.join(__dirname, dir) } const CompressionPlugin = require('compression-webpack-plugin') const name = process.env.VUE_APP_TITLE || 'BillionMes管ç†ç³»ç»Ÿ' // ç½‘é¡µæ ‡é¢˜ 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, transpileDependencies: ['quill'], // webpack-dev-server 相关é…ç½® devServer: { host: '0.0.0.0', port: port, open: true, proxy: { // detail: https://cli.vuejs.org/config/#devserver-proxy [process.env.VUE_APP_BASE_API]: { target: `http://localhost:8080`, changeOrigin: true, pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' } } }, disableHostCheck: true }, css: { loaderOptions: { sass: { sassOptions: { outputStyle: "expanded" } } } }, configureWebpack: { name: name, resolve: { alias: { '@': resolve('src') } }, plugins: [ // http://doc.ruoyi.vip/ruoyi-vue/other/faq.html#使用gzip解压缩é™æ€æ–‡ä»¶ new CompressionPlugin({ cache: false, // ä¸å¯ç”¨æ–‡ä»¶ç¼“å˜ test: /\.(js|css|html|jpe?g|png|gif|svg)?$/i, // åŽ‹ç¼©æ–‡ä»¶æ ¼å¼ filename: '[path][base].gz[query]', // 压缩åŽçš„文件å algorithm: 'gzip', // 使用gzip压缩 minRatio: 0.8, // 压缩比例,å°äºŽ 80% 的文件ä¸ä¼šè¢«åŽ‹ç¼© deleteOriginalAssets: false // 压缩åŽåˆ 除原文件 }) ], }, 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() 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 test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm priority: 20 // the weight needs to be larger than libs and app or it will be packaged into libs or app }, 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') }) } }