12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- const path = require('path');
- const CompressionWebpackPlugin = require("compression-webpack-plugin")
- const productionGzipExtensions = ['js', 'css']
- function resolve(dir) {
- return path.join(__dirname, dir)
- }
- let title = '';
- if (process.env.VUE_APP_NODE_NAME == 'production') {
- title = ''
- } else if (process.env.VUE_APP_NODE_NAME == 'test') {
- title = '(测试)'
- } else {
- title = '(开发)'
- }
- const Timestamp = new Date().getTime();
- const config = {
- //商业园区
- business: {
- pages: {
- index: {
- entry: 'src/projects/business/main.js',
- template: 'index/business/index.html',
- filename: 'index.html',
- title: '湖北新生源生物工程有限公司' + title,
- }
- },
- outputDir: 'dist',
- devServer: {
- host: '0.0.0.0',
- port: 8080,
- //解析缓存
- disableHostCheck: true,
- //支持gzip
- compress: true,
- },
- chainWebpack: (config) => {
- config.entry.app = ['babel-polyfill', '../src/projects/business/main.js']
- config.resolve.alias
- .set('@', resolve('../src/projects/business/'))
- .set('$project', resolve('../src/'))
- .set('$root', resolve('../'))
- config.plugins.delete('preload-index');
- config.plugins.delete('prefetch-index');
- config.optimization.minimize(true);
- //打包分析添加
- //config.output.filename('js/[name].[hash].js').end();
- //config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
- },
- configureWebpack: config => {
- //开启gzip压缩,需要配置Nginx服务器gzip选项开启
- config.plugins.push(
- new CompressionWebpackPlugin({
- algorithm: 'gzip', //开启gzip
- test: /\.js$|\.html$|.\css/, // 匹配文件名
- threshold: 10240, // 对超过10k的数据压缩
- deleteOriginalAssets: false // 不删除源文件
- })
- );
- config.output.filename = `./static/js/[name].${Timestamp}.js`
- config.output.chunkFilename = `./static/js/[name].${Timestamp}.js`
- config.performance = {
- hints: 'warning',
- //入口起点的最大体积 整数类型(以字节为单位)
- maxEntrypointSize: 50000000,
- //生成文件的最大体积 整数类型(以字节为单位 300k)
- maxAssetSize: 30000000,
- //只给出 js 文件的性能提示
- assetFilter: function(assetFilename) {
- return assetFilename.endsWith('.js');
- }
- }
- },
- }
- }
- const configObj = config["business"]
- module.exports = configObj
|