vue.config.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. const path = require('path')
  2. const webpack = require('webpack')
  3. const CompressionWebpackPlugin = require("compression-webpack-plugin");
  4. function resolve(dir) {
  5. return path.join(__dirname, dir)
  6. }
  7. // vue.config.js
  8. module.exports = {
  9. pages: {
  10. index: {
  11. // page 的入口
  12. entry: 'src/main.js',
  13. // 模板来源
  14. template: 'public/index.html',
  15. // 在 dist/index.html 的输出
  16. filename: 'index.html',
  17. // 当使用 title 选项时,
  18. // template 中的 title 标签需要是 <title><%= htmlWebpackPlugin.options.title %></title>
  19. title: '河北省住建处大数据服务系统',
  20. // 在这个页面中包含的块,默认情况下会包含
  21. // 提取出来的通用 chunk 和 vendor chunk。
  22. chunks: ['chunk-vendors', 'chunk-common', 'index']
  23. }
  24. },
  25. // ...other config
  26. configureWebpack: config => {
  27. config.performance = {
  28. hints: 'warning',
  29. //入口起点的最大体积 整数类型(以字节为单位)
  30. maxEntrypointSize: 50000000,
  31. //生成文件的最大体积 整数类型(以字节为单位 300k)
  32. maxAssetSize: 30000000,
  33. //只给出 js 文件的性能提示
  34. assetFilter: function (assetFilename) {
  35. return assetFilename.endsWith('.js')
  36. }
  37. }
  38. const plugins = [];
  39. // 同externals一样,我们只想在生产环境下生成gzip即可
  40. if (process.env.NODE_ENV === 'production') {
  41. plugins.push(
  42. new CompressionWebpackPlugin({
  43. filename: '[path].gz[query]', // 生成的文件名
  44. algorithm: 'gzip', // 类型
  45. test: new RegExp('\\.(js|css)$'), // 匹配规则
  46. threshold: 10240, // 字节数 只处理比这个大的资源
  47. minRatio: 0.8, // 压缩率 只有比这个小的才会处理
  48. // 是否删除源文件,默认: false
  49. deleteOriginalAssets: false
  50. })
  51. )
  52. }
  53. config.plugins = [
  54. ...config.plugins,
  55. ...plugins
  56. ]
  57. let rules = [{
  58. test: /\.geojson$/,
  59. loader: 'json-loader'
  60. }]
  61. config.module.rules = [
  62. ...config.module.rules,
  63. ...rules
  64. ]
  65. },
  66. // {
  67. // // webpack plugins
  68. // plugins: [
  69. // // Ignore all locale files of moment.js
  70. // new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
  71. // new CompressionWebpackPlugin({
  72. // filename: '[path].gz[query]', // 生成的文件名
  73. // algorithm: 'gzip', // 类型
  74. // test: new RegExp('\\.(js|css)$'), // 匹配规则
  75. // threshold: 10240, // 字节数 只处理比这个大的资源
  76. // minRatio: 0.8 // 压缩率 只有比这个小的才会处理
  77. // })
  78. // ],
  79. // module: {
  80. // rules: [{
  81. // test: /\.geojson$/,
  82. // loader: 'json-loader'
  83. // }]
  84. // }
  85. // },
  86. productionSourceMap: false, //打包不生成js.map文件
  87. chainWebpack: (config) => {
  88. config.resolve.alias
  89. .set('@$', resolve('src'))
  90. .set('@static', resolve('public/static'))
  91. },
  92. css: {
  93. loaderOptions: {
  94. less: {
  95. modifyVars: {
  96. 'primary-color': '#F05A28',
  97. 'border-color-base': '#F05A28',
  98. 'heading-color': 'rgba(240, 90, 40, 1)',
  99. 'link-color': '#F05A28'
  100. },
  101. javascriptEnabled: true
  102. },
  103. }
  104. },
  105. pluginOptions: {
  106. "style-resources-loader": {
  107. preProcessor: "less",
  108. patterns: [
  109. path.resolve(__dirname, 'src/assets/less/variable.less')
  110. ]
  111. }
  112. },
  113. devServer: {
  114. port: 1002,
  115. proxy: {
  116. '/proxy_oauth/': {
  117. target: 'http://121.43.55.7:10086',
  118. changeOrigin: true,
  119. pathRewrite: {
  120. '^/proxy_oauth': ''
  121. }
  122. },
  123. '/proxy_data/': {
  124. target: 'http://121.43.55.7:10087',
  125. changeOrigin: true,
  126. pathRewrite: {
  127. '^/proxy_data': ''
  128. }
  129. },
  130. // '/proxy_data/': {
  131. // target: 'http://192.168.1.61:10087',
  132. // changeOrigin: true,
  133. // pathRewrite: {
  134. // '^/proxy_data': ''
  135. // }
  136. // },
  137. '/proxy_mark/': {
  138. target: 'http://121.43.55.7:10088',
  139. changeOrigin: true,
  140. pathRewrite: {
  141. '^/proxy_mark': ''
  142. }
  143. },
  144. }
  145. }
  146. }