vue.config.js 5.2 KB

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