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

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