vue.config.js配置表
javascript
1const path = require('path') 2module.exports = { 3 // 基本路径 4 /* 部署生产环境和开发环境下的URL:可对当前环境进行区分,baseUrl 从 Vue CLI 3.3 起已弃用,要使用publicPath */ 5 /* baseUrl: process.env.NODE_ENV === 'production' ? './' : '/' */ 6 publicPath: process.env.NODE_ENV === 'production' ? '/' : './', 7 // 输出文件目录 8 outputDir: 'dist', 9 // eslint-loader 是否在保存的时候检查 10 lintOnSave: false, 11 // use the full build with in-browser compiler? 12 // https://vuejs.org/v2/guide/installation.html#Runtime-Compiler-vs-Runtime-only 13 // compiler: false, 14 runtimeCompiler: true, // 关键点在这 15 // 调整内部的 webpack 配置。 16 // 查阅 https://github.com/vuejs/vue-doc-zh-cn/vue-cli/webpack.md 17 // webpack配置 18 // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md 19 chainWebpack: () => {}, 20 configureWebpack: config => { 21 if (process.env.NODE_ENV === 'production') { 22 // 为生产环境修改配置... 23 config.mode = 'production' 24 // 将每个依赖包打包成单独的js文件 25 var optimization = { 26 runtimeChunk: 'single', 27 splitChunks: { 28 chunks: 'all', 29 maxInitialRequests: Infinity, 30 minSize: 20000, // 依赖包超过20000bit将被单独打包 31 cacheGroups: { 32 vendor: { 33 test: /[\\/]node_modules[\\/]/, 34 name (module) { 35 // get the name. E.g. node_modules/packageName/not/this/part.js 36 // or node_modules/packageName 37 const packageName = module.context.match( 38 /[\\/]node_modules[\\/](.*?)([\\/]|$)/ 39 )[1] 40 // npm package names are URL-safe, but some servers don't like @ symbols 41 return `npm.${packageName.replace('@', '')}` 42 } 43 } 44 } 45 } 46 } 47 Object.assign(config, { 48 optimization 49 }) 50 } else { 51 // 为开发环境修改配置... 52 config.mode = 'development' 53 var optimization2 = { 54 runtimeChunk: 'single', 55 splitChunks: { 56 chunks: 'all', 57 maxInitialRequests: Infinity, 58 minSize: 20000, // 依赖包超过20000bit将被单独打包 59 cacheGroups: { 60 vendor: { 61 test: /[\\/]node_modules[\\/]/, 62 name (module) { 63 // get the name. E.g. node_modules/packageName/not/this/part.js 64 // or node_modules/packageName 65 const packageName = module.context.match( 66 /[\\/]node_modules[\\/](.*?)([\\/]|$)/ 67 )[1] 68 // npm package names are URL-safe, but some servers don't like @ symbols 69 return `npm.${packageName.replace('@', '')}` 70 } 71 } 72 } 73 } 74 } 75 } 76 Object.assign(config, { 77 // 开发生产共同配置 78 79 // externals: { 80 // 'vue': 'Vue', 81 // 'element-ui': 'ELEMENT', 82 // 'vue-router': 'VueRouter', 83 // 'vuex': 'Vuex' 84 // } // 防止将某些 import 的包(package)打包到 bundle 中,而是在运行时(runtime)再去从外部获取这些扩展依赖(用于csdn引入) 85 resolve: { 86 extensions: ['.js', '.vue', '.json'], // 文件优先解析后缀名顺序 87 alias: { 88 '@': path.resolve(__dirname, './src'), 89 '@c': path.resolve(__dirname, './src/components'), 90 '@v': path.resolve(__dirname, './src/views'), 91 '@u': path.resolve(__dirname, './src/utils'), 92 '@s': path.resolve(__dirname, './src/service') 93 }, // 别名配置 94 plugins: [] 95 }, 96 optimization: optimization2 97 }) 98 }, 99 // vue-loader 配置项 100 // https://vue-loader.vuejs.org/en/options.html 101 // vueLoader: {}, 102 // 生产环境是否生成 sourceMap 文件 103 productionSourceMap: false, 104 // css相关配置 105 css: { 106 // 是否使用css分离插件 ExtractTextPlugin 107 // extract: true, //注释css热更新生效 108 // 开启 CSS source maps? 109 sourceMap: false, 110 // css预设器配置项 111 loaderOptions: {}, 112 // 启用 CSS modules for all css / pre-processor files. 113 modules: false 114 }, 115 // use thread-loader for babel & TS in production build 116 // enabled by default if the machine has more than 1 cores 117 parallel: require('os').cpus().length > 1, 118 // 是否启用dll 119 // See https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#dll-mode 120 // dll: false, 121 // PWA 插件相关配置 122 // see https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa 123 pwa: {}, 124 // webpack-dev-server 相关配置 125 devServer: { 126 /* 自动打开浏览器 */ 127 open: true, 128 // host: "192.168.0.137", 129 port: 9090, 130 https: false, 131 hotOnly: false, 132 /* 使用代理 */ 133 proxy: { 134 '/api': { 135 /* 目标代理服务器地址 */ 136 // target: "http://192.168.0.106:8080/", 137 target: 'http://192.168.1.126:8080/', 138 /* 允许跨域 */ 139 changeOrigin: true, 140 ws: true, 141 pathRewrite: { 142 '^/api': '' 143 } 144 } 145 }, 146 before: () => {} 147 }, 148 // 第三方插件配置 149 pluginOptions: {} 150} 151
阅读量:3517发布日期:2021-06-11 16:59:36
博客描述
vue.config.js配置表