vue.config.js 2.4 KB

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