vue.config.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. // host: "swings.pim.com",
  21. // open: true,
  22. overlay: {
  23. warnings: false,
  24. errors: true
  25. },
  26. public: "0.0.0.0:9557", //可以实现热部署
  27. proxy: {
  28. // [process.env.VUE_APP_OAUTH_API]: {
  29. // target: `http://localhost:19090/sso`,
  30. // changeOrigin: true,
  31. // // logLevel: 'debug', //打印日志
  32. // pathRewrite: {
  33. // ['^' + process.env.VUE_APP_OAUTH_API]: ''
  34. // }
  35. // },
  36. // [process.env.VUE_APP_PIM_API]: {
  37. // target: `http://localhost:18080/pim`,
  38. // changeOrigin: true,
  39. // // logLevel: 'debug', //打印日志
  40. // pathRewrite: {
  41. // ['^' + process.env.VUE_APP_PIM_API]: ''
  42. // }
  43. // },
  44. // [process.env.VUE_APP_OMS_API]: {
  45. // target: `http://localhost:18081/oms`,
  46. // changeOrigin: true,
  47. // // logLevel: 'debug', //打印日志
  48. // pathRewrite: {
  49. // ['^' + process.env.VUE_APP_OMS_API]: ''
  50. // }
  51. // }
  52. "/": {
  53. // target: "http://10.41.3.106:9093",
  54. target: "https://portal.gloria.com.cn",
  55. changeOrigin: true
  56. },
  57. }
  58. },
  59. // webpack配置
  60. configureWebpack: {
  61. name: name,
  62. resolve: {
  63. alias: {
  64. "@": resolve("src")
  65. }
  66. }
  67. },
  68. chainWebpack(config) {
  69. // 删除预加载
  70. config.plugins.delete("preload"); // TODO: need test
  71. config.plugins.delete("prefetch"); // TODO: need test
  72. // set svg-sprite-loader
  73. config.module
  74. .rule("svg")
  75. .exclude.add(resolve("src/icons"))
  76. .end();
  77. config.module
  78. .rule("icons")
  79. .test(/\.svg$/)
  80. .include.add(resolve("src/icons"))
  81. .end()
  82. .use("svg-sprite-loader")
  83. .loader("svg-sprite-loader")
  84. .options({
  85. symbolId: "icon-[name]"
  86. })
  87. .end();
  88. // set preserveWhitespace
  89. config.module
  90. .rule("vue")
  91. .use("vue-loader")
  92. .loader("vue-loader")
  93. .tap(options => {
  94. options.compilerOptions.preserveWhitespace = true;
  95. return options;
  96. })
  97. .end();
  98. config
  99. // https://webpack.js.org/configuration/devtool/#development
  100. .when(process.env.NODE_ENV === "development", config =>
  101. config.devtool("cheap-source-map")
  102. );
  103. config.when(process.env.NODE_ENV !== "development", config => {
  104. //非开发环境
  105. config
  106. .plugin("ScriptExtHtmlWebpackPlugin")
  107. .after("html")
  108. .use("script-ext-html-webpack-plugin", [
  109. {
  110. // `runtime` must same as runtimeChunk name. default is `runtime`
  111. inline: /runtime\..*\.js$/
  112. }
  113. ])
  114. .end();
  115. // 分割代码
  116. config.optimization.splitChunks({
  117. chunks: "all",
  118. cacheGroups: {
  119. libs: {
  120. name: "chunk-libs",
  121. test: /[\\/]node_modules[\\/]/,
  122. priority: 10,
  123. chunks: "initial" // only package third parties that are initially dependent
  124. },
  125. elementUI: {
  126. name: "chunk-elementUI", // split elementUI into a single package
  127. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  128. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  129. },
  130. commons: {
  131. name: "chunk-commons",
  132. test: resolve("src/components"), // can customize your rules
  133. minChunks: 3, // minimum common number
  134. priority: 5,
  135. reuseExistingChunk: false
  136. }
  137. }
  138. });
  139. config.optimization.runtimeChunk("single");
  140. });
  141. }
  142. };