vue.config.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. const path = require('path');
  2. const webpack = require('webpack')
  3. const CompressionWebpackPlugin = require("compression-webpack-plugin")
  4. const productionGzipExtensions = ['js', 'css']
  5. function resolve(dir) {
  6. return path.join(__dirname, dir)
  7. }
  8. const Timestamp = new Date().getTime();
  9. module.exports = {
  10. publicPath: './',
  11. outputDir: 'dist/' ,
  12. assetsDir: 'static',
  13. lintOnSave: false,
  14. devServer: {
  15. host: 'localhost',
  16. port: 8080,
  17. //解析缓存
  18. disableHostCheck: true,
  19. //支持gzip
  20. compress: true,
  21. },
  22. //不输出map
  23. productionSourceMap: false,
  24. chainWebpack: (config) => {
  25. config.entry.app = ['babel-polyfill', './src/main.js']
  26. config.resolve.alias
  27. .set('@', resolve('./static/'))
  28. config.plugins.delete('preload-index');
  29. config.plugins.delete('prefetch-index');
  30. config.module.rule('images')
  31. .test(/\.(png|jpe?g|gif|webp)(\?.*)?$/)
  32. .use('url-loader')
  33. .loader('file-loader')
  34. .options({
  35. name: 'static/img/[name].[hash:8].[ext]'
  36. })
  37. config.optimization.minimize(true);
  38. },
  39. configureWebpack: config => {
  40. /* //开启gzip压缩,需要配置Nginx服务器gzip选项开启
  41. config.plugins.push(
  42. new CompressionWebpackPlugin({
  43. filename: '[path].gz[query]',
  44. algorithm: 'gzip',
  45. test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
  46. threshold: 10240,
  47. minRatio: 0.8
  48. })
  49. ); */
  50. config.plugins.push(new webpack.ProgressPlugin(percentage => {
  51. percentage === 1 ? console.log('编译完成:100.00%') : console.log(`编译进度:${(percentage * 100).toFixed(2)}%`)
  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. css: {
  68. extract: {
  69. filename: `./static/css/[name].${Timestamp}.css`,
  70. chunkFilename: `./static/css/[name].${Timestamp}.css`
  71. },
  72. sourceMap: false,
  73. loaderOptions: {
  74. // 给 sass-loader 传递选项
  75. sass: {
  76. // @/ 是 src/ 的别名
  77. // prependData: `@import "@/assets/scss/base.scss";`
  78. }
  79. }
  80. }
  81. };