vue.config.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. const path = require('path')
  2. const CompressionPlugin = require('compression-webpack-plugin')
  3. function resolve(dir) {
  4. return path.join(__dirname, dir)
  5. }
  6. // vue.config.js
  7. module.exports = {
  8. // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
  9. productionSourceMap: false,
  10. configureWebpack: (config) => {
  11. // 生产环境取消 console.log
  12. if (process.env.NODE_ENV === 'production') {
  13. config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
  14. }
  15. },
  16. chainWebpack: (config) => {
  17. config.resolve.alias
  18. .set('@$', resolve('src'))
  19. .set('@api', resolve('src/api'))
  20. .set('@assets', resolve('src/assets'))
  21. .set('@comp', resolve('src/components'))
  22. .set('@views', resolve('src/views'))
  23. // 生产环境,开启js\css压缩
  24. if (process.env.NODE_ENV === 'production') {
  25. config.plugin('compressionPlugin').use(
  26. new CompressionPlugin({
  27. test: /\.(js|css|less)$/, // 匹配文件名
  28. threshold: 10240, // 对超过10k的数据压缩
  29. deleteOriginalAssets: false, // 删除源文件
  30. })
  31. )
  32. }
  33. },
  34. css: {
  35. loaderOptions: {
  36. less: {
  37. modifyVars: {
  38. /* less 变量覆盖,用于自定义 ant design 主题 */
  39. 'primary-color': '#1890FF',
  40. 'link-color': '#1890FF',
  41. 'border-radius-base': '4px',
  42. },
  43. javascriptEnabled: true,
  44. },
  45. },
  46. },
  47. devServer: {
  48. port: 80,
  49. proxy: {
  50. '/jshERP-boot': {
  51. target: 'http://localhost:8080', // 请求本地 需要jshERP-boot后台项目
  52. ws: false,
  53. changeOrigin: true,
  54. },
  55. },
  56. },
  57. lintOnSave: undefined,
  58. }