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

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