pages.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const path = require('path');
  2. const CompressionWebpackPlugin = require("compression-webpack-plugin")
  3. const productionGzipExtensions = ['js', 'css']
  4. function resolve(dir) {
  5. return path.join(__dirname, dir)
  6. }
  7. let title = '';
  8. if (process.env.VUE_APP_NODE_NAME == 'production') {
  9. title = ''
  10. } else if (process.env.VUE_APP_NODE_NAME == 'test') {
  11. title = '(测试)'
  12. } else {
  13. title = '(开发)'
  14. }
  15. const Timestamp = new Date().getTime();
  16. const config = {
  17. //商业园区
  18. business: {
  19. pages: {
  20. index: {
  21. entry: 'src/projects/business/main.js',
  22. template: 'index/business/index.html',
  23. filename: 'index.html',
  24. title: '湖北新生源生物工程有限公司' + title,
  25. }
  26. },
  27. outputDir: 'dist',
  28. devServer: {
  29. host: '0.0.0.0',
  30. port: 8080,
  31. //解析缓存
  32. disableHostCheck: true,
  33. //支持gzip
  34. compress: true,
  35. },
  36. chainWebpack: (config) => {
  37. config.entry.app = ['babel-polyfill', '../src/projects/business/main.js']
  38. config.resolve.alias
  39. .set('@', resolve('../src/projects/business/'))
  40. .set('$project', resolve('../src/'))
  41. .set('$root', resolve('../'))
  42. config.plugins.delete('preload-index');
  43. config.plugins.delete('prefetch-index');
  44. config.optimization.minimize(true);
  45. //打包分析添加
  46. //config.output.filename('js/[name].[hash].js').end();
  47. //config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  48. },
  49. configureWebpack: config => {
  50. //开启gzip压缩,需要配置Nginx服务器gzip选项开启
  51. config.plugins.push(
  52. new CompressionWebpackPlugin({
  53. algorithm: 'gzip', //开启gzip
  54. test: /\.js$|\.html$|.\css/, // 匹配文件名
  55. threshold: 10240, // 对超过10k的数据压缩
  56. deleteOriginalAssets: false // 不删除源文件
  57. })
  58. );
  59. config.output.filename = `./static/js/[name].${Timestamp}.js`
  60. config.output.chunkFilename = `./static/js/[name].${Timestamp}.js`
  61. config.performance = {
  62. hints: 'warning',
  63. //入口起点的最大体积 整数类型(以字节为单位)
  64. maxEntrypointSize: 50000000,
  65. //生成文件的最大体积 整数类型(以字节为单位 300k)
  66. maxAssetSize: 30000000,
  67. //只给出 js 文件的性能提示
  68. assetFilter: function(assetFilename) {
  69. return assetFilename.endsWith('.js');
  70. }
  71. }
  72. },
  73. }
  74. }
  75. const configObj = config["business"]
  76. module.exports = configObj