vue.config.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. "use strict";
  2. const path = require("path");
  3. const defaultSettings = require("./src/settings.js");
  4. function resolve(dir) {
  5. return path.join(__dirname, dir);
  6. }
  7. const name = defaultSettings.title || "歌莉娅AI口播视频管理平台"; // 标题
  8. const port = process.env.port || process.env.npm_config_port || 9557; // 开发接口
  9. // 所有配置项描述 查看: https://cli.vuejs.org/config/
  10. module.exports = {
  11. publicPath: "./", // 基本路径
  12. outputDir: "dist", // 输出文件目录
  13. assetsDir: "static", // 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录。
  14. // 指定生成的 index.html 的输出路径 (相对于 outputDir)。也可以是一个绝对路径
  15. // indexPath: './',
  16. lintOnSave: process.env.NODE_ENV === "production", // lintOnSave: eslint-loader 是否在保存的时候检查
  17. productionSourceMap: false, // 生产环境是否生成 sourceMap 文件
  18. devServer: {
  19. port: port,
  20. // open: true,
  21. overlay: {
  22. warnings: false,
  23. errors: true
  24. },
  25. public: "0.0.0.0:9557", //可以实现热部署
  26. proxy: {
  27. // "/video-service": {
  28. // target: "http://60.165.238.181:8189/",
  29. // changeOrigin: true,
  30. // pathRewrite: {
  31. // "^/video-service": ""
  32. // }
  33. // },
  34. "/app": {
  35. // target: "http://10.41.3.106:9093",
  36. target: "https://portal.gloria.com.cn",
  37. changeOrigin: true
  38. }
  39. }
  40. },
  41. // webpack配置
  42. configureWebpack: {
  43. name: name,
  44. resolve: {
  45. alias: {
  46. "@": resolve("src")
  47. }
  48. }
  49. },
  50. chainWebpack(config) {
  51. // 删除预加载
  52. config.plugins.delete("preload"); // TODO: need test
  53. config.plugins.delete("prefetch"); // TODO: need test
  54. // set svg-sprite-loader
  55. config.module
  56. .rule("svg")
  57. .exclude.add(resolve("src/icons"))
  58. .end();
  59. config.module
  60. .rule("icons")
  61. .test(/\.svg$/)
  62. .include.add(resolve("src/icons"))
  63. .end()
  64. .use("svg-sprite-loader")
  65. .loader("svg-sprite-loader")
  66. .options({
  67. symbolId: "icon-[name]"
  68. })
  69. .end();
  70. // set preserveWhitespace
  71. config.module
  72. .rule("vue")
  73. .use("vue-loader")
  74. .loader("vue-loader")
  75. .tap(options => {
  76. options.compilerOptions.preserveWhitespace = true;
  77. return options;
  78. })
  79. .end();
  80. config
  81. // https://webpack.js.org/configuration/devtool/#development
  82. .when(process.env.NODE_ENV === "development", config =>
  83. config.devtool("cheap-source-map")
  84. );
  85. config.when(process.env.NODE_ENV !== "development", config => {
  86. //非开发环境
  87. config
  88. .plugin("ScriptExtHtmlWebpackPlugin")
  89. .after("html")
  90. .use("script-ext-html-webpack-plugin", [
  91. {
  92. // `runtime` must same as runtimeChunk name. default is `runtime`
  93. inline: /runtime\..*\.js$/
  94. }
  95. ])
  96. .end();
  97. // 分割代码
  98. config.optimization.splitChunks({
  99. chunks: "all",
  100. cacheGroups: {
  101. libs: {
  102. name: "chunk-libs",
  103. test: /[\\/]node_modules[\\/]/,
  104. priority: 10,
  105. chunks: "initial" // only package third parties that are initially dependent
  106. },
  107. elementUI: {
  108. name: "chunk-elementUI", // split elementUI into a single package
  109. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  110. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  111. },
  112. commons: {
  113. name: "chunk-commons",
  114. test: resolve("src/components"), // can customize your rules
  115. minChunks: 3, // minimum common number
  116. priority: 5,
  117. reuseExistingChunk: false
  118. }
  119. }
  120. });
  121. config.optimization.runtimeChunk("single");
  122. });
  123. }
  124. };