数字化园区前端项目
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 3.1KB

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