vue.config.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 || "管乐迷后台管理系统"; // 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 methods:
  12. // port = 9528 npm run dev OR npm run dev --port = 9528
  13. // const port = process.env.port || process.env.npm_config_port || 9528 // dev port
  14. // http://47.99.212.176:8000
  15. // https://online.dayaedu.com
  16. // let target = "https://online.dayaedu.com"; //线上
  17. // let target = 'http://192.168.3.251:8000' // 何国威
  18. // let target = 'http://192.168.3.20:8000' //邹璇
  19. // let target = 'http://192.168.3.161:8000' //勇哥
  20. // let target = 'http://192.168.3.146:8000' //王昭
  21. // let target = 'http://dev.dayaedu.com' // 开发环境
  22. let target = "https://test.dayaedu.com"; //测试环境
  23. // let target = "https://online.dayaedu.com"; //测试环境
  24. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  25. module.exports = {
  26. /**
  27. * You will need to set publicPath if you plan to deploy your site under a sub path,
  28. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  29. * then publicPath should be set to "/bar/".
  30. * In most cases please use '/' !!!
  31. * Detail: https://cli.vuejs.org/config/#publicpath
  32. */
  33. publicPath: "./",
  34. outputDir: "dist",
  35. assetsDir: "static",
  36. lintOnSave: false,
  37. productionSourceMap: false,
  38. // 以下是pwa配置
  39. pwa: {
  40. iconPaths: {
  41. favicon32: "favicon1.ico",
  42. favicon16: "favicon1.ico",
  43. appleTouchIcon: "favicon1.ico",
  44. maskIcon: "favicon1.ico",
  45. msTileImage: "favicon1.ico"
  46. }
  47. },
  48. devServer: {
  49. disableHostCheck: true,
  50. open: false,
  51. hot: true,
  52. port: 3005,
  53. // overlay: {
  54. // warnings: false,
  55. // errors: true
  56. // },
  57. // https: true,
  58. proxy: {
  59. // change xxx-api/login => mock/login
  60. // detail: https://cli.vuejs.org/config/#devserver-proxy
  61. // http://47.99.212.176:8000
  62. // http://192.168.3.28:8000
  63. // http://192.168.3.134
  64. // http://47.114.176.40:8000
  65. // let target = 'http://dev.dayaedu.com'
  66. // 'http://dev.dayaedu.com'
  67. "/api-auth": {
  68. target: target,
  69. // target : target,
  70. changeOrigin: true,
  71. pathRewrite: {
  72. "^api-auth": ""
  73. }
  74. },
  75. "/api-task": {
  76. target: target,
  77. changeOrigin: true,
  78. pathRewrite: {
  79. "^api-task": ""
  80. }
  81. },
  82. "/api-web": {
  83. target: target,
  84. changeOrigin: true,
  85. pathRewrite: {
  86. "^api-web": ""
  87. }
  88. },
  89. "/api-cms": {
  90. target: target,
  91. changeOrigin: true,
  92. pathRewrite: {
  93. "^api-cms": ""
  94. }
  95. },
  96. "/api-teacher": {
  97. target: target,
  98. changeOrigin: true,
  99. pathRewrite: {
  100. "^api-teacher": ""
  101. }
  102. },
  103. "/api-oa": {
  104. target: target,
  105. changeOrigin: true,
  106. pathRewrite: {
  107. "^api-oa": ""
  108. }
  109. },
  110. "/jiari": {
  111. target: "http://tool.bitefu.net",
  112. changeOrigin: true
  113. },
  114. "/instructions": {
  115. target: defaultSettings.instructions,
  116. changeOrigin: true
  117. }
  118. // instructions
  119. }
  120. },
  121. configureWebpack: {
  122. // provide the app's title in webpack's name field, so that
  123. // it can be accessed in index.html to inject the correct title.
  124. name: name,
  125. resolve: {
  126. alias: {
  127. "@": resolve("src"),
  128. "@scss": path.resolve(__dirname, "src")
  129. }
  130. }
  131. },
  132. chainWebpack(config) {
  133. config.plugins.delete("preload"); // TODO: need test
  134. config.plugins.delete("prefetch"); // TODO: need test
  135. config.resolve.symlinks(true);
  136. // set svg-sprite-loader
  137. config.module
  138. .rule("svg")
  139. .exclude.add(resolve("src/icons"))
  140. .end();
  141. config.module
  142. .rule("icons")
  143. .test(/\.svg$/)
  144. .include.add(resolve("src/icons"))
  145. .end()
  146. .use("svg-sprite-loader")
  147. .loader("svg-sprite-loader")
  148. .options({
  149. symbolId: "icon-[name]"
  150. })
  151. .end();
  152. // set preserveWhitespace
  153. config.module
  154. .rule("vue")
  155. .use("vue-loader")
  156. .loader("vue-loader")
  157. .tap(options => {
  158. // Vue 项目需要添加过滤自定义组件配置。
  159. options.compilerOptions = {
  160. ...options.compilerOptions,
  161. isCustomElement: tag => {
  162. return (
  163. ["conversation-list", "message-list", "message-editor"].indexOf(
  164. tag
  165. ) !== -1
  166. );
  167. }
  168. };
  169. options.compilerOptions.preserveWhitespace = true;
  170. return options;
  171. })
  172. .end();
  173. config
  174. // https://webpack.js.org/configuration/devtool/#development
  175. .when(process.env.NODE_ENV === "development", config =>
  176. config.devtool("cheap-source-map")
  177. );
  178. config.when(process.env.NODE_ENV !== "development", config => {
  179. config
  180. .plugin("ScriptExtHtmlWebpackPlugin")
  181. .after("html")
  182. .use("script-ext-html-webpack-plugin", [
  183. {
  184. // `runtime` must same as runtimeChunk name. default is `runtime`
  185. inline: /runtime\..*\.js$/
  186. }
  187. ])
  188. .end();
  189. config.optimization.splitChunks({
  190. chunks: "all",
  191. cacheGroups: {
  192. libs: {
  193. name: "chunk-libs",
  194. test: /[\\/]node_modules[\\/]/,
  195. priority: 10,
  196. chunks: "initial" // only package third parties that are initially dependent
  197. },
  198. elementUI: {
  199. name: "chunk-elementUI", // split elementUI into a single package
  200. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  201. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  202. },
  203. commons: {
  204. name: "chunk-commons",
  205. test: resolve("src/components"), // can customize your rules
  206. minChunks: 3, // minimum common number
  207. priority: 5,
  208. reuseExistingChunk: true
  209. }
  210. }
  211. });
  212. config.optimization.runtimeChunk("single");
  213. });
  214. }
  215. };