vue.config.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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/app",
  54. changeOrigin: true
  55. },
  56. }
  57. },
  58. // webpack配置
  59. configureWebpack: {
  60. name: name,
  61. resolve: {
  62. alias: {
  63. "@": resolve("src")
  64. }
  65. }
  66. },
  67. chainWebpack(config) {
  68. // 删除预加载
  69. config.plugins.delete("preload"); // TODO: need test
  70. config.plugins.delete("prefetch"); // TODO: need test
  71. // set svg-sprite-loader
  72. config.module
  73. .rule("svg")
  74. .exclude.add(resolve("src/icons"))
  75. .end();
  76. config.module
  77. .rule("icons")
  78. .test(/\.svg$/)
  79. .include.add(resolve("src/icons"))
  80. .end()
  81. .use("svg-sprite-loader")
  82. .loader("svg-sprite-loader")
  83. .options({
  84. symbolId: "icon-[name]"
  85. })
  86. .end();
  87. // set preserveWhitespace
  88. config.module
  89. .rule("vue")
  90. .use("vue-loader")
  91. .loader("vue-loader")
  92. .tap(options => {
  93. options.compilerOptions.preserveWhitespace = true;
  94. return options;
  95. })
  96. .end();
  97. config
  98. // https://webpack.js.org/configuration/devtool/#development
  99. .when(process.env.NODE_ENV === "development", config =>
  100. config.devtool("cheap-source-map")
  101. );
  102. config.when(process.env.NODE_ENV !== "development", config => {
  103. //非开发环境
  104. config
  105. .plugin("ScriptExtHtmlWebpackPlugin")
  106. .after("html")
  107. .use("script-ext-html-webpack-plugin", [
  108. {
  109. // `runtime` must same as runtimeChunk name. default is `runtime`
  110. inline: /runtime\..*\.js$/
  111. }
  112. ])
  113. .end();
  114. // 分割代码
  115. config.optimization.splitChunks({
  116. chunks: "all",
  117. cacheGroups: {
  118. libs: {
  119. name: "chunk-libs",
  120. test: /[\\/]node_modules[\\/]/,
  121. priority: 10,
  122. chunks: "initial" // only package third parties that are initially dependent
  123. },
  124. elementUI: {
  125. name: "chunk-elementUI", // split elementUI into a single package
  126. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  127. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  128. },
  129. commons: {
  130. name: "chunk-commons",
  131. test: resolve("src/components"), // can customize your rules
  132. minChunks: 3, // minimum common number
  133. priority: 5,
  134. reuseExistingChunk: false
  135. }
  136. }
  137. });
  138. config.optimization.runtimeChunk("single");
  139. });
  140. }
  141. };