vue.config.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const path = require("path");
  2. const CompressionWebpackPlugin = require("compression-webpack-plugin");
  3. const isProd = process.env.NODE_ENV === "production";
  4. function resolve(dir) {
  5. return path.join(__dirname, dir);
  6. }
  7. module.exports = {
  8. publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
  9. chainWebpack: (config) => {
  10. config.resolve.alias.set("@", resolve("src"));
  11. },
  12. configureWebpack: (config) => {
  13. /* gzip压缩,nginx需要开启gzip*/
  14. if (isProd) {
  15. // 配置webpack 压缩
  16. config.plugins.push(
  17. new CompressionWebpackPlugin({
  18. test: /\.js$|\.html$|\.css$/,
  19. // 超过4kb压缩
  20. threshold: 4096,
  21. })
  22. );
  23. }
  24. // 添加 CDN 配置
  25. config.plugins.forEach((plugin) => {
  26. if (plugin.constructor.name === 'HtmlWebpackPlugin') {
  27. plugin.options.cdn = {
  28. js: []
  29. };
  30. }
  31. });
  32. },
  33. devServer: {
  34. open: true,
  35. https: false,
  36. proxy: {
  37. "/api": {
  38. target: "http://18.163.50.191:19005/api",
  39. changeOrigin: true,
  40. pathRewrite: {
  41. "^/api": "",
  42. },
  43. },
  44. },
  45. },
  46. };