vue.config.js 2.7 KB

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