vue.config.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. const CompressionPlugin = require('compression-webpack-plugin');
  2. const webpack = require('webpack');
  3. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  4. module.exports = {
  5. publicPath: process.env.NODE_ENV === 'production' ? '' : '/',
  6. productionSourceMap: false,
  7. lintOnSave: false,
  8. chainWebpack: config => {
  9. if (process.env.NODE_ENV === 'production') {
  10. if (process.env.npm_config_report) {
  11. config
  12. .plugin('webpack-bundle-analyzer')
  13. .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  14. }
  15. config.plugins.delete('prefetch');
  16. }
  17. },
  18. configureWebpack: config => {
  19. if (process.env.NODE_ENV === 'production') {
  20. config.optimization = {
  21. splitChunks: {
  22. chunks: "all", //async异步代码分割 initial同步代码分割 all同步异步分割都开启
  23. minSize: 10000, //字节 引入的文件大于30kb才进行分割
  24. // minChunks: 2, //模块至少使用次数
  25. // maxAsyncRequests: 25, //同时加载的模块数量最多是5个,只分割出同时引入的前5个文件
  26. // maxInitialRequests: 30, //首页加载的时候引入的文件最多3个
  27. automaticNameDelimiter: '-', //缓存组和生成文件名称之间的连接符
  28. // name: true, //缓存组里面的filename生效,覆盖默认命名
  29. cacheGroups: {
  30. // vue: {
  31. // name: "vue",
  32. // test: /[\\/]node_modules[\\/]vue[\\/]/,
  33. // test: /[\\/]node_modules[\\/]vue[\\/]/,
  34. // priority: -10
  35. // },
  36. // vuex: {
  37. // name: 'vuex',
  38. // test: /[\\/]node_modules[\\/]vuex[\\/]/,
  39. // priority: -10
  40. // },
  41. // 'vue-router': {
  42. // name: 'vue-router',
  43. // test: /[\\/]node_modules[\\/]vue-router[\\/]/,
  44. // priority: -10
  45. // },
  46. // 'element-ui': {
  47. // name: 'element-ui',
  48. // test: /[\\/]node_modules[\\/]element-ui[\\/]/,
  49. // priority: -10
  50. // },
  51. // vendors: {
  52. // test: /[\\\/]node_modules[\\\/]/,
  53. // priority: -20
  54. // },
  55. }
  56. }
  57. }
  58. // return {
  59. // plugins: [
  60. // new CompressionPlugin({
  61. // test: /\.js$|\.html$|\.css$/,
  62. // threshold: 10240,
  63. // deleteOriginalAssets: false,
  64. // }),
  65. // new webpack.optimize.MinChunkSizePlugin({
  66. // minChunkSize: 10000 // Minimum number of characters
  67. // }),
  68. // new WebpackLifeCyclePlugin(),
  69. // new BundleAnalyzerPlugin()
  70. // ]
  71. // }
  72. // config.plugins = [
  73. // new CompressionPlugin({
  74. // test: /\.js$|\.html$|\.css$/,
  75. // threshold: 10240,
  76. // deleteOriginalAssets: true,
  77. // }),
  78. // new webpack.optimize.MinChunkSizePlugin({
  79. // minChunkSize: 10000 // Minimum number of characters
  80. // }),
  81. // new WebpackLifeCyclePlugin(),
  82. // // new BundleAnalyzerPlugin()
  83. // ]
  84. }
  85. },
  86. parallel: true,
  87. devServer: {
  88. proxy: {
  89. '/': {
  90. // target: 'http://192.168.2.145:9600/spfm',
  91. // target: 'http://192.168.2.149:9600',
  92. // target: 'http://10.64.42.70:8088/',
  93. target: 'http://114.215.71.182:29600/',
  94. // target: 'http://192.168.2.135:9600/',
  95. // target: 'http://192.168.2.169:9600/',
  96. // target: 'http://192.168.2.170:9600/',
  97. // target: 'http://192.168.2.169:9600/',
  98. changeOrigin: true
  99. }
  100. }
  101. },
  102. transpileDependencies: ['color-string'] // 此段为增加配置选项
  103. }