数字化园区前端项目
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vue.config.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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://localhost:80",
  26. target: "http://192.168.18.236:18888/",
  27. // target: "http://192.168.30.48:18888/",
  28. // target: "http://192.168.18.138:18888/",
  29. changeOrigin: true,
  30. pathRewrite: {
  31. "^/domain": "",
  32. },
  33. },
  34. },
  35. },
  36. chainWebpack: config => {
  37. // 修复热更新
  38. config.resolve.symlinks(true);
  39. // 添加别名
  40. config.resolve.alias
  41. .set("@", resolve("./src"))
  42. .set("@assets", resolve("./src/assets"))
  43. .set("@api", resolve("./src/api"))
  44. .set("@utils", resolve("./src/utils"))
  45. .set("@components", resolve("./src/components"))
  46. .set("@views", resolve("./src/views"))
  47. .set("@mixin", resolve("./src/mixin"));
  48. },
  49. css: {
  50. loaderOptions: {
  51. sass: {
  52. // 根据自己样式文件的位置调整
  53. prependData: `@import "@assets/scss/global.scss";`, //这里的@是别名
  54. },
  55. },
  56. },
  57. configureWebpack: config => {
  58. config.optimization = {
  59. runtimeChunk: true,
  60. };
  61. const plugins = [];
  62. if (IS_PROD) {
  63. plugins.push(
  64. // 开启gzip
  65. new CompressionWebpackPlugin({
  66. filename: "[path].gz[query]",
  67. algorithm: "gzip",
  68. test: productionGzipExtensions,
  69. threshold: 10240,
  70. minRatio: 0.8,
  71. })
  72. // new BundleAnalyzer()
  73. );
  74. }
  75. config.plugins = [...config.plugins, ...plugins];
  76. },
  77. };