vue.config.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. const path = require('path')
  2. const CompressionPlugin = require('compression-webpack-plugin')
  3. const TerserPlugin = require("terser-webpack-plugin");
  4. const devServerPort = 3000
  5. const devServerHost = process.env.HOST || '0.0.0.0'
  6. const devServerPublic = process.env.VUE_APP_DEV_PUBLIC || `localhost:${devServerPort}`
  7. const devServerSockHost = process.env.VUE_APP_DEV_SOCK_HOST || devServerPublic.split(':')[0]
  8. const devServerSockPort = Number(process.env.VUE_APP_DEV_SOCK_PORT || devServerPublic.split(':')[1] || devServerPort)
  9. function resolve(dir) {
  10. return path.join(__dirname, dir)
  11. }
  12. // var appData = require('./json/video.json')//加载本地数据文件
  13. // vue.config.js
  14. module.exports = {
  15. /*
  16. Vue-cli3:
  17. Crashed when using Webpack `import()` #2463
  18. https://github.com/vuejs/vue-cli/issues/2463
  19. */
  20. // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
  21. productionSourceMap: false,
  22. /*
  23. pages: {
  24. index: {
  25. entry: 'src/main.js',
  26. chunks: ['chunk-vendors', 'chunk-common', 'index']
  27. }
  28. },
  29. */
  30. configureWebpack: () => {
  31. if (process.env.NODE_ENV === 'production') {
  32. return {
  33. plugins: [new CompressionPlugin({
  34. test: /\.js$|\.html$|\.css/,
  35. threshold: 10240,
  36. deleteOriginalAssets: false
  37. }), new TerserPlugin({
  38. cache: true,//降版本后添加
  39. sourceMap: false,//降版本后添加
  40. // 多进程
  41. parallel: true,//降版本后添加
  42. terserOptions: {
  43. ecma: undefined,
  44. warnings: false,
  45. parse: {},
  46. compress: {
  47. drop_console: true,
  48. drop_debugger: false,
  49. pure_funcs: ['console.log'], // 移除console
  50. },
  51. },
  52. }),]
  53. }
  54. }
  55. },
  56. chainWebpack: (config) => {
  57. config.resolve.alias
  58. .set('@$', resolve('src'))
  59. .set('@base', resolve('src/base'))
  60. .set('@api', resolve('src/api'))
  61. .set('@assets', resolve('src/assets'))
  62. .set('@comp', resolve('src/components'))
  63. .set('@views', resolve('src/views'))
  64. .set('@layout', resolve('src/layout'))
  65. .set('@static', resolve('src/static'));
  66. config.plugins.delete('prefetch')
  67. },
  68. pluginOptions: {
  69. 'style-resources-loader': {
  70. preProcessor: 'less',
  71. patterns: [
  72. resolve('src/styles/var.less'),
  73. resolve('src/styles/mixin.less')
  74. ]
  75. }
  76. },
  77. css: {
  78. loaderOptions: {
  79. less: {
  80. modifyVars: {
  81. /* less 变量覆盖,用于自定义 ant design 主题 */
  82. /*
  83. 'primary-color': '#F5222D',
  84. 'link-color': '#F5222D',
  85. 'border-radius-base': '4px',
  86. */
  87. },
  88. javascriptEnabled: true,
  89. }
  90. }
  91. },
  92. devServer: {
  93. hot: true,
  94. // inline: true,
  95. host: devServerHost,
  96. port: devServerPort,
  97. public: devServerPublic,
  98. sockHost: devServerSockHost,
  99. sockPort: devServerSockPort,
  100. disableHostCheck: true,
  101. open: true,
  102. proxy: {
  103. '/jeecg-boot/material': {
  104. target: 'http://127.0.0.1:7006',
  105. ws: false,
  106. changeOrigin: true,
  107. pathRewrite: {
  108. '^/jeecg-boot/material': '/material'
  109. }
  110. },
  111. '/jeecg-boot': {
  112. target: 'http://127.0.0.1:7001', //请求本地 需要jeecg-boot后台项目 蒙蒙
  113. // target: 'http://api.bjhcstszkj.cn', //请求本地 需要jeecg-boot后台项目
  114. ws: false,
  115. // changeOrigin: true,
  116. // pathRewrite: {
  117. // '/jeecg-boot': '' //默认所有请求都加了jeecg-boot前缀,需要去掉
  118. // }
  119. },
  120. '/material': {
  121. target: 'http://127.0.0.1:7006',
  122. ws: false,
  123. changeOrigin: true
  124. },
  125. },
  126. // before(app) {
  127. // app.get('/seller', (req, res) => {
  128. // res.json({
  129. // errno: 0,
  130. // data: appData
  131. // })//接口返回json数据,上面配置的数据seller就赋值给data请求后调用
  132. // })
  133. // }
  134. },
  135. lintOnSave: undefined,
  136. // publicPath:'./',
  137. }