vue.config.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. // 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. // http://47.99.212.176:8000
  41. // http://192.168.3.28:8000
  42. // http://192.168.3.134
  43. // http://47.114.176.40:8000
  44. // let target = 'http://dev.dayaedu.com'
  45. // 'http://dev.dayaedu.com'
  46. "/api-auth": {
  47. target: target,
  48. // target : target,
  49. changeOrigin: true,
  50. pathRewrite: {
  51. "^api-auth": "",
  52. },
  53. },
  54. "/api-task": {
  55. target: target,
  56. changeOrigin: true,
  57. pathRewrite: {
  58. "^api-task": "",
  59. },
  60. },
  61. "/api-oa": {
  62. target: target,
  63. changeOrigin: true,
  64. pathRewrite: {
  65. "^api-task": "",
  66. },
  67. },
  68. "/api-web": {
  69. target: target,
  70. changeOrigin: true,
  71. pathRewrite: {
  72. "^api-web": "",
  73. },
  74. },
  75. "/api-cms": {
  76. target: target,
  77. changeOrigin: true,
  78. pathRewrite: {
  79. "^api-cms": "",
  80. },
  81. },
  82. "/api-teacher": {
  83. target: target,
  84. changeOrigin: true,
  85. pathRewrite: {
  86. "^api-teacher": "",
  87. },
  88. },
  89. "/jiari": {
  90. target: "http://tool.bitefu.net",
  91. changeOrigin: true,
  92. },
  93. },
  94. },
  95. configureWebpack: {
  96. plugins: [new MonacoWebpackPlugin()],
  97. name: name,
  98. resolve: {
  99. alias: {
  100. "@": resolve("src"),
  101. },
  102. },
  103. },
  104. chainWebpack(config) {
  105. config.plugins.delete("preload"); // TODO: need test
  106. config.plugins.delete("prefetch"); // TODO: need test
  107. // set svg-sprite-loader
  108. config.module.rule("svg").exclude.add(resolve("src/icons")).end();
  109. config.module
  110. .rule("icons")
  111. .test(/\.svg$/)
  112. .include.add(resolve("src/icons"))
  113. .end()
  114. .use("svg-sprite-loader")
  115. .loader("svg-sprite-loader")
  116. .options({
  117. symbolId: "icon-[name]",
  118. })
  119. .end();
  120. // set preserveWhitespace
  121. config.module
  122. .rule("vue")
  123. .use("vue-loader")
  124. .loader("vue-loader")
  125. .tap((options) => {
  126. options.compilerOptions.preserveWhitespace = true;
  127. return options;
  128. })
  129. .end();
  130. config
  131. // https://webpack.js.org/configuration/devtool/#development
  132. .when(process.env.NODE_ENV === "development", (config) =>
  133. config.devtool("cheap-source-map")
  134. );
  135. config.when(process.env.NODE_ENV !== "development", (config) => {
  136. config
  137. .plugin("ScriptExtHtmlWebpackPlugin")
  138. .after("html")
  139. .use("script-ext-html-webpack-plugin", [
  140. {
  141. // `runtime` must same as runtimeChunk name. default is `runtime`
  142. inline: /runtime\..*\.js$/,
  143. },
  144. ])
  145. .end();
  146. config.optimization.splitChunks({
  147. chunks: "all",
  148. cacheGroups: {
  149. libs: {
  150. name: "chunk-libs",
  151. test: /[\\/]node_modules[\\/]/,
  152. priority: 10,
  153. chunks: "initial", // only package third parties that are initially dependent
  154. },
  155. elementUI: {
  156. name: "chunk-elementUI", // split elementUI into a single package
  157. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  158. test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
  159. },
  160. commons: {
  161. name: "chunk-commons",
  162. test: resolve("src/components"), // can customize your rules
  163. minChunks: 3, // minimum common number
  164. priority: 5,
  165. reuseExistingChunk: true,
  166. },
  167. },
  168. });
  169. config.optimization.runtimeChunk("single");
  170. });
  171. },
  172. };