vue.config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. const { defineConfig } = require('@vue/cli-service')
  2. const path = require('path')
  3. const webpack = require('webpack')
  4. const CompressionWebpackPlugin = require("compression-webpack-plugin");
  5. function resolve(dir) {
  6. return path.join(__dirname, dir)
  7. }
  8. module.exports = defineConfig({
  9. transpileDependencies: true,
  10. pages: {
  11. index: {
  12. // page 的入口
  13. entry: 'src/main.js',
  14. // 模板来源
  15. template: 'public/index.html',
  16. // 在 dist/index.html 的输出
  17. filename: 'index.html',
  18. // 当使用 title 选项时,
  19. // template 中的 title 标签需要是 <title><%= htmlWebpackPlugin.options.title %></title>
  20. title: '青浦政务服务中心',
  21. // 在这个页面中包含的块,默认情况下会包含
  22. // 提取出来的通用 chunk 和 vendor chunk。
  23. chunks: ['chunk-vendors', 'chunk-common', 'index']
  24. }
  25. },
  26. // ...other config
  27. configureWebpack: config => {
  28. config.performance = {
  29. hints: 'warning',
  30. //入口起点的最大体积 整数类型(以字节为单位)
  31. maxEntrypointSize: 50000000,
  32. //生成文件的最大体积 整数类型(以字节为单位 300k)
  33. maxAssetSize: 30000000,
  34. //只给出 js 文件的性能提示
  35. assetFilter: function (assetFilename) {
  36. return assetFilename.endsWith('.js')
  37. }
  38. }
  39. const plugins = [];
  40. // 同externals一样,我们只想在生产环境下生成gzip即可
  41. if (process.env.NODE_ENV === 'production') {
  42. plugins.push(
  43. new CompressionWebpackPlugin({
  44. filename: '[path][base].gz[query]', // 生成的文件名
  45. algorithm: 'gzip', // 类型
  46. test: new RegExp('\\.(js|css)$'), // 匹配规则
  47. threshold: 10240, // 字节数 只处理比这个大的资源
  48. minRatio: 0.8, // 压缩率 只有比这个小的才会处理
  49. // 是否删除源文件,默认: false
  50. deleteOriginalAssets: false
  51. })
  52. )
  53. }
  54. config.plugins = [
  55. ...config.plugins,
  56. ...plugins
  57. ]
  58. // 增加加载 .geojson 文件的规则
  59. let rules = [{
  60. test: /\.geojson$/,
  61. loader: 'json-loader'
  62. }]
  63. config.module.rules = [
  64. ...config.module.rules,
  65. ...rules
  66. ]
  67. },
  68. productionSourceMap: false, //打包不生成js.map文件
  69. chainWebpack: (config) => {
  70. config.resolve.alias
  71. .set('@$', resolve('src'))
  72. .set('@static', resolve('public/static'))
  73. },
  74. pluginOptions: {
  75. "style-resources-loader": {
  76. preProcessor: "less",
  77. patterns: [
  78. path.resolve(__dirname, 'src/assets/less/variable.less')
  79. ]
  80. },
  81. },
  82. devServer: {
  83. port: 2011,
  84. proxy: {
  85. '/proxy_oauth/': {
  86. target: "http://szlszxdt.qpservice.org.cn",
  87. changeOrigin: true,
  88. pathRewrite: {
  89. '^/proxy_oauth': ''
  90. }
  91. }
  92. }
  93. }
  94. })