vue.config.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. const {
  2. defineConfig
  3. } = require('@vue/cli-service');
  4. const dev_baseURL = 'https://www.waywish.com';
  5. const isProduction = process.env.NODE_ENV === 'production'; //是否为生产环境
  6. const path = require("path");
  7. const Happypack = require('happypack');
  8. const resolve = (dir) => {
  9. return path.join(__dirname, dir);
  10. }
  11. module.exports = defineConfig({
  12. publicPath: './',
  13. outputDir: '../src/main/resources/static/workark',
  14. assetsDir: 'static',
  15. lintOnSave: false,
  16. productionSourceMap: false,
  17. // webpack配置
  18. // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
  19. chainWebpack: config => {
  20. // 移除 prefetch 插件
  21. config.plugins.delete('prefetch')
  22. // 移除 preload 插件
  23. config.plugins.delete('preload');
  24. // 生产环境配置
  25. if (isProduction) {
  26. // 压缩代码
  27. config.optimization.minimize(true);
  28. // 分割代码
  29. config.optimization.splitChunks({
  30. chunks: 'all'
  31. })
  32. }
  33. },
  34. configureWebpack: {
  35. devtool: process.env.NODE_ENV === 'development' ? 'eval' : false,
  36. plugins: [
  37. new Happypack({
  38. loaders: ['babel-loader', 'vue-loader'],
  39. cache: true,
  40. threads: 10 // 线程数取决于你电脑性能的好坏,好的电脑建议开更多线程
  41. })
  42. ]
  43. },
  44. devServer: {
  45. port: 8080, // 端口
  46. open: false, // 自动开启浏览器
  47. compress: false, // 开启压缩
  48. hot: true, // 模块热替换
  49. client: {
  50. overlay: { // 当出现编译错误或警告时,在浏览器中显示全屏覆盖。
  51. warnings: true,
  52. errors: true
  53. },
  54. progress: true, // 在浏览器中以百分比形式打印编译进度。
  55. },
  56. proxy: {
  57. '/v1': {
  58. target: dev_baseURL,
  59. changeOrigin: true,
  60. ws: true,
  61. pathRewrite: {
  62. '^/v1': ''
  63. }
  64. }
  65. }
  66. },
  67. // css相关配置
  68. css: {
  69. // css预设器配置项
  70. loaderOptions: {
  71. // pass options to sass-loader
  72. sass: {
  73. // 引入全局变量样式
  74. prependData: `
  75. @import "@/assets/css/element-variables.scss";
  76. `
  77. }
  78. },
  79. }
  80. })