调整打包方式区分压缩 未压缩
This commit is contained in:
parent
fbe1da2a08
commit
35208da27f
@ -1,5 +1,5 @@
|
|||||||
# just a flag
|
# just a flag
|
||||||
NODE_ENV = 'Local'
|
NODE_ENV = 'production'
|
||||||
VUE_APP_PRO = 'local'
|
VUE_APP_PRO = 'local'
|
||||||
|
|
||||||
# base api
|
# base api
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# just a flag
|
# just a flag
|
||||||
NODE_ENV = 'test'
|
NODE_ENV = 'production'
|
||||||
|
|
||||||
# base api
|
# base api
|
||||||
VUE_APP_BASE_API = 'https://test.joylink.club/jlcloud'
|
VUE_APP_BASE_API = 'https://test.joylink.club/jlcloud'
|
||||||
|
@ -9,13 +9,6 @@ const webpack = require('webpack');
|
|||||||
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
||||||
// http://127.0.0.1:8888/ 分析打包模块可视化
|
// 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 name = defaultSettings.title; // page title
|
||||||
const port = 9527; // dev port
|
const port = 9527; // dev port
|
||||||
|
|
||||||
@ -32,7 +25,6 @@ module.exports = {
|
|||||||
outputDir: 'dist',
|
outputDir: 'dist',
|
||||||
assetsDir: 'static', // 相对于outputDir的静态资源(js、css、img、fonts)目录
|
assetsDir: 'static', // 相对于outputDir的静态资源(js、css、img、fonts)目录
|
||||||
lintOnSave: false,
|
lintOnSave: false,
|
||||||
// filenameHashing: true,
|
|
||||||
productionSourceMap: false, // 项目打包后是否压缩
|
productionSourceMap: false, // 项目打包后是否压缩
|
||||||
devServer: {
|
devServer: {
|
||||||
port: port,
|
port: port,
|
||||||
@ -64,44 +56,35 @@ module.exports = {
|
|||||||
// },
|
// },
|
||||||
// parallel: require('os').cpus().length > 1, // 是否为 Babel 或 TypeScript 使用 thread-loader。该选项在系统的 CPU 有多于一个内核时自动启用,仅作用于生产构建。
|
// parallel: require('os').cpus().length > 1, // 是否为 Babel 或 TypeScript 使用 thread-loader。该选项在系统的 CPU 有多于一个内核时自动启用,仅作用于生产构建。
|
||||||
configureWebpack: config => {
|
configureWebpack: config => {
|
||||||
// if (process.env.NODE_ENV === 'production') {
|
const appTarget = process.env.VUE_APP_PRO == 'local' ? 'HYD' : 'Common'; // 其他环境变量 区分配置
|
||||||
// // 为生产环境修改配置...
|
|
||||||
// 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';
|
|
||||||
config.plugins.push(new webpack.NormalModuleReplacementPlugin(/(.*)_APP_TARGET(\.*)/,
|
config.plugins.push(new webpack.NormalModuleReplacementPlugin(/(.*)_APP_TARGET(\.*)/,
|
||||||
function (resourse) {
|
function (resourse) {
|
||||||
resourse.request = resourse.request.replace(/APP_TARGET/, `${appTarget}`);
|
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([
|
config.plugins.push(new CopyWebpackPlugin([
|
||||||
{
|
{
|
||||||
from: path.resolve(__dirname, './static'),
|
from: path.resolve(__dirname, './static'),
|
||||||
@ -110,15 +93,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
]));
|
]));
|
||||||
// config.plugins.push(new BundleAnalyzerPlugin());
|
// config.plugins.push(new BundleAnalyzerPlugin());
|
||||||
const externalsConfig = {
|
config.externals = {}; // 配置CDN使用
|
||||||
// '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使用
|
|
||||||
},
|
},
|
||||||
// webpack配置
|
// webpack配置
|
||||||
chainWebpack(config) {
|
chainWebpack(config) {
|
||||||
@ -184,39 +159,32 @@ module.exports = {
|
|||||||
test: /[\\/]node_modules[\\/]/,
|
test: /[\\/]node_modules[\\/]/,
|
||||||
name(module) {
|
name(module) {
|
||||||
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
|
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
|
||||||
return `chunk.${packageName.replace('@', '')}`;
|
return `split-chunk.${packageName.replace('@', '')}`;
|
||||||
},
|
},
|
||||||
priority: 10, // 缓存组优先级 数字越⼤大,优先级越⾼高
|
priority: 10, // 缓存组优先级 数字越⼤大,优先级越⾼高
|
||||||
reuseExistingChunk: true // 如果当前代码块包含的模块已经有了,就不在产生一个新的代码块
|
reuseExistingChunk: true // 如果当前代码块包含的模块已经有了,就不在产生一个新的代码块
|
||||||
},
|
},
|
||||||
jlmap: {
|
jlmap: {
|
||||||
name: 'jlmap',
|
name: 'split-jlmap',
|
||||||
test: path.resolve(__dirname, './src/jmap'),
|
test: path.resolve(__dirname, './src/jmap'),
|
||||||
priority: 8,
|
priority: 8,
|
||||||
minChunks: 1,
|
minChunks: 1,
|
||||||
reuseExistingChunk: true
|
reuseExistingChunk: true
|
||||||
},
|
},
|
||||||
jmapNew: {
|
jmapNew: {
|
||||||
name: 'jmapNew',
|
name: 'split-jmapNew',
|
||||||
test: path.resolve(__dirname, './src/jmapNew'),
|
test: path.resolve(__dirname, './src/jmapNew'),
|
||||||
priority: 9,
|
priority: 9,
|
||||||
minChunks: 1,
|
minChunks: 1,
|
||||||
reuseExistingChunk: true
|
reuseExistingChunk: true
|
||||||
},
|
},
|
||||||
jlmap3d: {
|
jlmap3d: {
|
||||||
name: 'jlmap3d',
|
name: 'split-jlmap3d',
|
||||||
test: path.resolve(__dirname, './src/jlmap3d'),
|
test: path.resolve(__dirname, './src/jlmap3d'),
|
||||||
priority: 7,
|
priority: 7,
|
||||||
minChunks: 1,
|
minChunks: 1,
|
||||||
reuseExistingChunk: true
|
reuseExistingChunk: true
|
||||||
}
|
}
|
||||||
// ibp: {
|
|
||||||
// name: 'ibp',
|
|
||||||
// test: path.resolve(__dirname, './src/ibp'),
|
|
||||||
// priority: -10,
|
|
||||||
// minChunks: 1,
|
|
||||||
// reuseExistingChunk: true
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
config.optimization.runtimeChunk('single');
|
config.optimization.runtimeChunk('single');
|
||||||
|
Loading…
Reference in New Issue
Block a user