From 35208da27fb25bba03b8c162766d8f3bc4b90442 Mon Sep 17 00:00:00 2001 From: zyy <1787816799@qq.com> Date: Fri, 22 May 2020 10:13:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=89=93=E5=8C=85=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=8C=BA=E5=88=86=E5=8E=8B=E7=BC=A9=20=E6=9C=AA?= =?UTF-8?q?=E5=8E=8B=E7=BC=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.native | 2 +- .env.staging | 2 +- vue.config.js | 90 +++++++++++++++++---------------------------------- 3 files changed, 31 insertions(+), 63 deletions(-) diff --git a/.env.native b/.env.native index d1152d456..af5c4a6d3 100644 --- a/.env.native +++ b/.env.native @@ -1,5 +1,5 @@ # just a flag -NODE_ENV = 'Local' +NODE_ENV = 'production' VUE_APP_PRO = 'local' # base api diff --git a/.env.staging b/.env.staging index 605ec30ae..41dbe65d7 100644 --- a/.env.staging +++ b/.env.staging @@ -1,5 +1,5 @@ # just a flag -NODE_ENV = 'test' +NODE_ENV = 'production' # base api VUE_APP_BASE_API = 'https://test.joylink.club/jlcloud' diff --git a/vue.config.js b/vue.config.js index 9b52b7b4c..83f60744f 100644 --- a/vue.config.js +++ b/vue.config.js @@ -9,13 +9,6 @@ const webpack = require('webpack'); // const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; // http://127.0.0.1:8888/ 分析打包模块可视化 -// const CompressionPlugin = require('compression-webpack-plugin'); -// const productionGzipExtensions = ['js', 'css']; -// const isProduction = process.env.NODE_ENV === 'production'; - -// let { version } = require('./package.json'); -// version = version.replace(/\./g, '_'); - const name = defaultSettings.title; // page title const port = 9527; // dev port @@ -32,7 +25,6 @@ module.exports = { outputDir: 'dist', assetsDir: 'static', // 相对于outputDir的静态资源(js、css、img、fonts)目录 lintOnSave: false, - // filenameHashing: true, productionSourceMap: false, // 项目打包后是否压缩 devServer: { port: port, @@ -64,44 +56,35 @@ module.exports = { // }, // parallel: require('os').cpus().length > 1, // 是否为 Babel 或 TypeScript 使用 thread-loader。该选项在系统的 CPU 有多于一个内核时自动启用,仅作用于生产构建。 configureWebpack: config => { - // if (process.env.NODE_ENV === 'production') { - // // 为生产环境修改配置... - // config.mode = 'production'; - - // Object.assign(config, { - // output:{ - // ...config.output, - // filename: `static/js/[name].[chunkhash].${version}.js`, - // chunkFilename: `static/js/[name].[chunkhash].${version}.js` - // } - // }); - // // config.plugins = [ - // // ...config.plugins, - // // new CompressionPlugin({ - // // test:/\.js$|\.html$|.\css/, // 匹配文件名 - // // threshold: 10240, // 对超过10k的数据压缩 - // // deleteOriginalAssets: false // 不删除源文件 - // // }) - // // ]; - - // } else { - // // 为开发环境修改配置... - // config.mode = 'development'; - // } - config.name = name; - config.resolve = { - extensions: ['.js', '.vue', '.json'], - // modules: [path.resolve(__dirname, './node_modules')], - alias: { // 添加别名 - '@': path.resolve('src') - } - }; - const appTarget = process.env.NODE_ENV === 'Local' || process.env.VUE_APP_PRO === 'local' ? 'HYD' : 'Common'; + const appTarget = process.env.VUE_APP_PRO == 'local' ? 'HYD' : 'Common'; // 其他环境变量 区分配置 config.plugins.push(new webpack.NormalModuleReplacementPlugin(/(.*)_APP_TARGET(\.*)/, function (resourse) { resourse.request = resourse.request.replace(/APP_TARGET/, `${appTarget}`); }) ); + if (process.env.NODE_ENV != 'development') { + config.mode = 'production'; + + Object.assign(config, { + output:{ + ...config.output, + filename: `static/js/[name].[hash:6].js`, + chunkFilename: `static/js/[name].[chunkhash:6].js` + } + }); + } else { + // 为开发环境修改配置... + config.mode = 'development'; + config.name = name; + } + + config.resolve = { + extensions: ['.js', '.vue', '.json'], + alias: { // 添加别名 + '@': path.resolve('src') + } + }; + config.plugins.push(new CopyWebpackPlugin([ { from: path.resolve(__dirname, './static'), @@ -110,15 +93,7 @@ module.exports = { } ])); // config.plugins.push(new BundleAnalyzerPlugin()); - const externalsConfig = { - // 'vue': 'Vue', - // 'vuex': 'Vuex', - // 'vue-router': 'VueRouter', - // 'nprogress': 'NProgress', - // 'echarts': 'echarts', - // 'element-ui': 'ELEMENT' - }; - config.externals = process.env.NODE_ENV === 'Local' || process.env.VUE_APP_PRO === 'local' ? {} : externalsConfig; // 配置CDN使用 + config.externals = {}; // 配置CDN使用 }, // webpack配置 chainWebpack(config) { @@ -184,39 +159,32 @@ module.exports = { test: /[\\/]node_modules[\\/]/, name(module) { const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]; - return `chunk.${packageName.replace('@', '')}`; + return `split-chunk.${packageName.replace('@', '')}`; }, priority: 10, // 缓存组优先级 数字越⼤大,优先级越⾼高 reuseExistingChunk: true // 如果当前代码块包含的模块已经有了,就不在产生一个新的代码块 }, jlmap: { - name: 'jlmap', + name: 'split-jlmap', test: path.resolve(__dirname, './src/jmap'), priority: 8, minChunks: 1, reuseExistingChunk: true }, jmapNew: { - name: 'jmapNew', + name: 'split-jmapNew', test: path.resolve(__dirname, './src/jmapNew'), priority: 9, minChunks: 1, reuseExistingChunk: true }, jlmap3d: { - name: 'jlmap3d', + name: 'split-jlmap3d', test: path.resolve(__dirname, './src/jlmap3d'), priority: 7, minChunks: 1, reuseExistingChunk: true } - // ibp: { - // name: 'ibp', - // test: path.resolve(__dirname, './src/ibp'), - // priority: -10, - // minChunks: 1, - // reuseExistingChunk: true - // } } }); config.optimization.runtimeChunk('single');