vue.config.js 6.2 KB

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