vue.config.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. if(process.env.NODE_ENV === "production"){
  2. const path = require('path');
  3. const webpack = require('webpack')
  4. const CompressionWebpackPlugin = require("compression-webpack-plugin")
  5. const productionGzipExtensions = ['js', 'css']
  6. function resolve(dir) {
  7. return path.join(__dirname, dir)
  8. }
  9. const Timestamp = new Date().getTime();
  10. module.exports = {
  11. publicPath: './',
  12. outputDir: 'dist/' ,
  13. assetsDir: 'static',
  14. lintOnSave: false,
  15. devServer: {
  16. host: 'xpgj.xiaoxinda.com',
  17. port: 80,
  18. //解析缓存
  19. disableHostCheck: true,
  20. //支持gzip
  21. compress: true,
  22. },
  23. //不输出map
  24. productionSourceMap: false,
  25. chainWebpack: (config) => {
  26. config.entry.app = ['babel-polyfill', './src/main.js']
  27. config.resolve.alias
  28. .set('@', resolve('./static/'))
  29. config.plugins.delete('preload-index');
  30. config.plugins.delete('prefetch-index');
  31. config.module.rule('images')
  32. .test(/\.(png|jpe?g|gif|webp)(\?.*)?$/)
  33. .use('url-loader')
  34. .loader('file-loader')
  35. .options({
  36. name: 'static/img/[name].[hash:8].[ext]'
  37. })
  38. config.optimization.minimize(true);
  39. },
  40. configureWebpack: config => {
  41. /* //开启gzip压缩,需要配置Nginx服务器gzip选项开启
  42. config.plugins.push(
  43. new CompressionWebpackPlugin({
  44. filename: '[path].gz[query]',
  45. algorithm: 'gzip',
  46. test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
  47. threshold: 10240,
  48. minRatio: 0.8
  49. })
  50. ); */
  51. config.plugins.push(new webpack.ProgressPlugin(percentage => {
  52. percentage === 1 ? console.log('编译完成:100.00%') : console.log(`编译进度:${(percentage * 100).toFixed(2)}%`)
  53. }));
  54. config.output.filename = `./static/js/[name].${Timestamp}.js`
  55. config.output.chunkFilename = `./static/js/[name].${Timestamp}.js`
  56. config.performance = {
  57. hints: 'warning',
  58. //入口起点的最大体积 整数类型(以字节为单位)
  59. maxEntrypointSize: 50000000,
  60. //生成文件的最大体积 整数类型(以字节为单位 300k)
  61. maxAssetSize: 30000000,
  62. //只给出 js 文件的性能提示
  63. assetFilter: function(assetFilename) {
  64. return assetFilename.endsWith('.js');
  65. }
  66. }
  67. },
  68. css: {
  69. extract: {
  70. filename: `./static/css/[name].${Timestamp}.css`,
  71. chunkFilename: `./static/css/[name].${Timestamp}.css`
  72. },
  73. sourceMap: false,
  74. loaderOptions: {
  75. // 给 sass-loader 传递选项
  76. sass: {
  77. // @/ 是 src/ 的别名
  78. // prependData: `@import "@/assets/scss/base.scss";`
  79. }
  80. }
  81. }
  82. };
  83. }