vue.config.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 || "OA系统"; // page title
  8. // If your port is set to 80,
  9. // use administrator privileges to execute the command line.
  10. // For example, Mac: sudo npm run
  11. // You can change the port by the following method:
  12. // port = 9527 npm run dev OR npm run dev --port = 9527
  13. const port = process.env.port || process.env.npm_config_port || 9527; // dev port
  14. const MonacoWebpackPlugin = require("monaco-editor-webpack-plugin");
  15. const target = "https://test.gym.lexiaoya.cn";
  16. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  17. module.exports = {
  18. /**
  19. * You will need to set publicPath if you plan to deploy your site under a sub path,
  20. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  21. * then publicPath should be set to "/bar/".
  22. * In most cases please use '/' !!!
  23. * Detail: https://cli.vuejs.org/config/#publicpath
  24. */
  25. publicPath: "./",
  26. outputDir: "web",
  27. assetsDir: "static/web",
  28. lintOnSave: false, // process.env.NODE_ENV === 'development',
  29. productionSourceMap: false,
  30. devServer: {
  31. port: port,
  32. open: true,
  33. overlay: {
  34. warnings: false,
  35. errors: true,
  36. },
  37. proxy: {
  38. // change xxx-api/login => mock/login
  39. // detail: https://cli.vuejs.org/config/#devserver-proxy
  40. "/api-auth": {
  41. target: target,
  42. // target : target,
  43. // changeOrigin: true,
  44. pathRewrite: {
  45. "^api-auth": "",
  46. },
  47. },
  48. "/api-task": {
  49. target: target,
  50. changeOrigin: true,
  51. pathRewrite: {
  52. "^api-task": "",
  53. },
  54. },
  55. "/api-oa": {
  56. target: target,
  57. changeOrigin: true,
  58. pathRewrite: {
  59. "^api-task": "",
  60. },
  61. },
  62. "/api-web": {
  63. target: target,
  64. changeOrigin: true,
  65. pathRewrite: {
  66. "^api-web": "",
  67. },
  68. },
  69. "/api-cms": {
  70. target: target,
  71. changeOrigin: true,
  72. pathRewrite: {
  73. "^api-cms": "",
  74. },
  75. },
  76. "/api-teacher": {
  77. target: target,
  78. changeOrigin: true,
  79. pathRewrite: {
  80. "^api-teacher": "",
  81. },
  82. },
  83. "/jiari": {
  84. target: "http://tool.bitefu.net",
  85. changeOrigin: true,
  86. },
  87. },
  88. },
  89. configureWebpack: {
  90. plugins: [new MonacoWebpackPlugin()],
  91. name: name,
  92. resolve: {
  93. alias: {
  94. "@": resolve("src"),
  95. },
  96. },
  97. },
  98. chainWebpack(config) {
  99. config.plugins.delete("preload"); // TODO: need test
  100. config.plugins.delete("prefetch"); // TODO: need test
  101. // set svg-sprite-loader
  102. config.module.rule("svg").exclude.add(resolve("src/icons")).end();
  103. config.module
  104. .rule("icons")
  105. .test(/\.svg$/)
  106. .include.add(resolve("src/icons"))
  107. .end()
  108. .use("svg-sprite-loader")
  109. .loader("svg-sprite-loader")
  110. .options({
  111. symbolId: "icon-[name]",
  112. })
  113. .end();
  114. // set preserveWhitespace
  115. config.module
  116. .rule("vue")
  117. .use("vue-loader")
  118. .loader("vue-loader")
  119. .tap((options) => {
  120. options.compilerOptions.preserveWhitespace = true;
  121. return options;
  122. })
  123. .end();
  124. config
  125. // https://webpack.js.org/configuration/devtool/#development
  126. .when(process.env.NODE_ENV === "development", (config) =>
  127. config.devtool("cheap-source-map")
  128. );
  129. config.when(process.env.NODE_ENV !== "development", (config) => {
  130. config
  131. .plugin("ScriptExtHtmlWebpackPlugin")
  132. .after("html")
  133. .use("script-ext-html-webpack-plugin", [
  134. {
  135. // `runtime` must same as runtimeChunk name. default is `runtime`
  136. inline: /runtime\..*\.js$/,
  137. },
  138. ])
  139. .end();
  140. config.optimization.splitChunks({
  141. chunks: "all",
  142. cacheGroups: {
  143. libs: {
  144. name: "chunk-libs",
  145. test: /[\\/]node_modules[\\/]/,
  146. priority: 10,
  147. chunks: "initial", // only package third parties that are initially dependent
  148. },
  149. elementUI: {
  150. name: "chunk-elementUI", // split elementUI into a single package
  151. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  152. test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
  153. },
  154. commons: {
  155. name: "chunk-commons",
  156. test: resolve("src/components"), // can customize your rules
  157. minChunks: 3, // minimum common number
  158. priority: 5,
  159. reuseExistingChunk: true,
  160. },
  161. },
  162. });
  163. config.optimization.runtimeChunk("single");
  164. });
  165. },
  166. };