vue.config.js 6.1 KB

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