vue.config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. const path = require('path');
  2. const Timestamp = new Date().getTime();
  3. let title = '';
  4. if (process.env.VUE_APP_NODE_NAME == 'production') {
  5. title = ''
  6. } else if (process.env.VUE_APP_NODE_NAME == 'test') {
  7. title = '(测试)'
  8. } else {
  9. title = '(开发)'
  10. }
  11. const CompressionWebpackPlugin = require("compression-webpack-plugin")
  12. const productionGzipExtensions = ['js', 'css']
  13. const conf = {
  14. pages: {
  15. index: {
  16. entry: 'src/projects/main.js',
  17. template: 'index/business/index.html',
  18. filename: 'index.html',
  19. title: '小鹏管家' + title,
  20. }
  21. },
  22. outputDir: 'dist',
  23. devServer: {
  24. host: '0.0.0.0',
  25. port: 80,
  26. //解析缓存
  27. disableHostCheck: true,
  28. //支持gzip
  29. compress: true,
  30. },
  31. chainWebpack: (config) => {
  32. config.entry.app = ['babel-polyfill', '../src/projects/main.js']
  33. config.resolve.alias
  34. .set('$project', resolve('../src/projects/'))
  35. .set('@', resolve('../src/'))
  36. config.plugins.delete('preload-index');
  37. config.plugins.delete('prefetch-index');
  38. config.optimization.minimize(true);
  39. //打包分析添加
  40. //config.output.filename('js/[name].[hash].js').end();
  41. //config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  42. },
  43. configureWebpack: config => {
  44. //开启gzip压缩,需要配置Nginx服务器gzip选项开启
  45. config.plugins.push(
  46. new CompressionWebpackPlugin({
  47. algorithm: 'gzip', //开启gzip
  48. test: /\.js$|\.html$|.\css/, // 匹配文件名
  49. threshold: 10240, // 对超过10k的数据压缩
  50. deleteOriginalAssets: false // 不删除源文件
  51. })
  52. );
  53. config.output.filename = `./static/js/[name].${Timestamp}.js`
  54. config.output.chunkFilename = `./static/js/[name].${Timestamp}.js`
  55. config.performance = {
  56. hints: 'warning',
  57. //入口起点的最大体积 整数类型(以字节为单位)
  58. maxEntrypointSize: 50000000,
  59. //生成文件的最大体积 整数类型(以字节为单位 300k)
  60. maxAssetSize: 30000000,
  61. //只给出 js 文件的性能提示
  62. assetFilter: function(assetFilename) {
  63. return assetFilename.endsWith('.js');
  64. }
  65. }
  66. },
  67. };
  68. function resolve(dir) {
  69. return path.join(__dirname, dir)
  70. }
  71. module.exports = {
  72. pages: conf.pages,
  73. publicPath: './',
  74. outputDir: conf.outputDir + '_' + process.env.OUT_PUT_NAME,
  75. assetsDir: 'static',
  76. lintOnSave: false,
  77. devServer: conf.devServer,
  78. //不输出map
  79. productionSourceMap: false,
  80. chainWebpack: conf.chainWebpack,
  81. configureWebpack: conf.configureWebpack,
  82. css: {
  83. extract: {
  84. filename: `./static/css/[name].${Timestamp}.css`,
  85. chunkFilename: `./static/css/[name].${Timestamp}.css`
  86. },
  87. sourceMap: false,
  88. loaderOptions: {
  89. // 给 sass-loader 传递选项
  90. sass: {
  91. // @/ 是 src/ 的别名
  92. // prependData: `@import "@/assets/scss/base.scss";`
  93. }
  94. }
  95. }
  96. };