数字化园区前端项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vue.config.js 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. const path = require("path");
  2. const resolve = dir => path.join(__dirname, dir);
  3. const IS_PROD = ["production", "prod"].includes(process.env.NODE_ENV);
  4. const CompressionWebpackPlugin = require("compression-webpack-plugin");
  5. const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i;
  6. // 图形化打包详情
  7. // const BundleAnalyzer = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
  8. module.exports = {
  9. publicPath: "/", // 默认'/',部署应用包时的基本 URL
  10. outputDir: "dist", // 'dist', 生产环境构建文件的目录
  11. assetsDir: "pc", // 相对于outputDir的静态资源(js、css、img、fonts)目录
  12. lintOnSave: false,
  13. indexPath: "pc.html",
  14. runtimeCompiler: true, // 是否使用包含运行时编译器的 Vue 构建版本
  15. productionSourceMap: false, // 生产环境的 source map
  16. devServer: {
  17. open: true,
  18. index: "index.html", //默认启动serve 打开index页面
  19. port: 8089,
  20. https: false,
  21. hotOnly: false,
  22. disableHostCheck: true,
  23. proxy: {
  24. "/domain": {
  25. // target: "http://192.168.18.138:80",
  26. target: "http://localhost:80",
  27. changeOrigin: true,
  28. pathRewrite: {
  29. "^/domain": "",
  30. },
  31. },
  32. },
  33. },
  34. chainWebpack: config => {
  35. // 修复热更新
  36. config.resolve.symlinks(true);
  37. // 添加别名
  38. config.resolve.alias
  39. .set("@", resolve("./src"))
  40. .set("@assets", resolve("./src/assets"))
  41. .set("@api", resolve("./src/api"))
  42. .set("@utils", resolve("./src/utils"))
  43. .set("@components", resolve("./src/components"))
  44. .set("@views", resolve("./src/views"))
  45. .set("@customerService", resolve("./src/customerService"));
  46. // 移除prefetch
  47. config.plugins.delete("prefetch");
  48. config.plugins.delete("preload");
  49. },
  50. configureWebpack: config => {
  51. config.optimization = {
  52. runtimeChunk: true,
  53. };
  54. const plugins = [];
  55. if (IS_PROD) {
  56. plugins.push(
  57. // 开启gzip
  58. new CompressionWebpackPlugin({
  59. filename: "[path].gz[query]",
  60. algorithm: "gzip",
  61. test: productionGzipExtensions,
  62. threshold: 10240,
  63. minRatio: 0.8,
  64. })
  65. // new BundleAnalyzer()
  66. );
  67. }
  68. config.plugins = [...config.plugins, ...plugins];
  69. },
  70. };