vue.config.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. productionSourceMap: false, //打包不生成js.map文件
  67. chainWebpack: (config) => {
  68. config.resolve.alias
  69. .set('@$', resolve('src'))
  70. .set('@static', resolve('public/static'))
  71. },
  72. css: {
  73. loaderOptions: {
  74. less: {
  75. modifyVars: {},
  76. javascriptEnabled: true
  77. },
  78. }
  79. },
  80. pluginOptions: {
  81. "style-resources-loader": {
  82. preProcessor: "less",
  83. patterns: [
  84. path.resolve(__dirname, 'src/assets/common/less/variable.less')
  85. ]
  86. }
  87. },
  88. devServer: {
  89. port: 2010,
  90. proxy: {
  91. '/ojk_data': {
  92. target: 'http://122.228.13.28:5000',
  93. changeOrigin: true,
  94. pathRewrite: {
  95. '^/ojk_data': ''
  96. }
  97. },
  98. },
  99. proxy: {
  100. '/ojk_tiles': {
  101. target: 'http://121.43.55.7:65456',
  102. changeOrigin: true,
  103. pathRewrite: {
  104. '^/ojk_tiles': ''
  105. }
  106. },
  107. },
  108. }
  109. }