vue.config.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. "use strict";
  2. const path = require("path");
  3. const defaultSettings = require("./src/settings.js");
  4. /**
  5. * dart-sass 不支持 node-sass 遗留的 /deep/ 选择器。
  6. * 这里在编译期做等价转换(::v-deep 与 /deep/ 在 vue-loader 中处理结果一致),
  7. * 避免为了构建去修改业务代码。
  8. * 若环境使用原生 node-sass(如 Node 12 的 CI),require 失败则跳过,保持原有行为。
  9. */
  10. try {
  11. const sassImpl = require("sass");
  12. const sassRender = sassImpl.render.bind(sassImpl);
  13. const sassRenderSync = sassImpl.renderSync.bind(sassImpl);
  14. const convertDeepSelector = options => {
  15. if (options && typeof options.data === "string") {
  16. options.data = options.data.replace(/\/deep\//g, "::v-deep");
  17. }
  18. return options;
  19. };
  20. sassImpl.render = (options, callback) =>
  21. sassRender(convertDeepSelector(options), callback);
  22. sassImpl.renderSync = options => sassRenderSync(convertDeepSelector(options));
  23. } catch (e) {}
  24. function resolve(dir) {
  25. return path.join(__dirname, dir);
  26. }
  27. const name = defaultSettings.title || "管乐迷后台管理系统"; // page title
  28. // If your port is set to 80,
  29. // use administrator privileges to execute the command line.
  30. // For example, Mac: sudo npm run
  31. // You can change the port by the following methods:
  32. // port = 9528 npm run dev OR npm run dev --port = 9528
  33. // const port = process.env.port || process.env.npm_config_port || 9528 // dev port
  34. // http://47.99.212.176:8000
  35. // https://online.dayaedu.com
  36. // let target = "https://online.dayaedu.com"; //线上
  37. // let target = "http://192.168.3.43:8805"; //邹璇
  38. // let target = "http://192.168.0.127:8000"; //勇哥
  39. // let target = "http://192.168.3.14:8005"; // 原谅
  40. let target = "https://test.gym.lexiaoya.cn"; //测试环境
  41. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  42. module.exports = {
  43. /**
  44. * You will need to set publicPath if you plan to deploy your site under a sub path,
  45. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  46. * then publicPath should be set to "/bar/".
  47. * In most cases please use '/' !!!
  48. * Detail: https://cli.vuejs.org/config/#publicpath
  49. */
  50. publicPath: "./",
  51. outputDir: "dist",
  52. assetsDir: "static",
  53. lintOnSave: false,
  54. productionSourceMap: false,
  55. // 以下是pwa配置
  56. pwa: {
  57. iconPaths: {
  58. favicon32: "favicon1.ico",
  59. favicon16: "favicon1.ico",
  60. appleTouchIcon: "favicon1.ico",
  61. maskIcon: "favicon1.ico",
  62. msTileImage: "favicon1.ico"
  63. }
  64. },
  65. devServer: {
  66. disableHostCheck: true,
  67. open: false,
  68. hot: true,
  69. port: 3005,
  70. // overlay: {
  71. // warnings: false,
  72. // errors: true
  73. // },
  74. // https: true,
  75. proxy: {
  76. // change xxx-api/login => mock/login
  77. // detail: https://cli.vuejs.org/config/#devserver-proxy
  78. // http://47.99.212.176:8000
  79. // http://192.168.3.28:8000
  80. // http://192.168.3.134
  81. // http://47.114.176.40:8000
  82. // let target = 'http://dev.dayaedu.com'
  83. // 'http://dev.dayaedu.com'
  84. "/api-auth": {
  85. target: target,
  86. // target : target,
  87. changeOrigin: true,
  88. pathRewrite: {
  89. "^api-auth": ""
  90. }
  91. },
  92. "/api-task": {
  93. target: target,
  94. changeOrigin: true,
  95. pathRewrite: {
  96. "^api-task": ""
  97. }
  98. },
  99. "/api-web": {
  100. target: target,
  101. changeOrigin: true,
  102. pathRewrite: {
  103. "^api-web": ""
  104. }
  105. },
  106. "/api-cms": {
  107. target: target,
  108. changeOrigin: true,
  109. pathRewrite: {
  110. "^api-cms": ""
  111. }
  112. },
  113. "/api-teacher": {
  114. target: target,
  115. changeOrigin: true,
  116. pathRewrite: {
  117. "^api-teacher": ""
  118. }
  119. },
  120. "/api-oa": {
  121. target: target,
  122. changeOrigin: true,
  123. pathRewrite: {
  124. "^api-oa": ""
  125. }
  126. },
  127. "/jiari": {
  128. target: "http://tool.bitefu.net",
  129. changeOrigin: true
  130. },
  131. "/instructions": {
  132. target: defaultSettings.instructions,
  133. changeOrigin: true
  134. }
  135. // instructions
  136. }
  137. },
  138. configureWebpack: {
  139. // provide the app's title in webpack's name field, so that
  140. // it can be accessed in index.html to inject the correct title.
  141. name: name,
  142. resolve: {
  143. alias: {
  144. "@": resolve("src"),
  145. "@scss": path.resolve(__dirname, "src")
  146. }
  147. }
  148. },
  149. chainWebpack(config) {
  150. config.plugins.delete("preload"); // TODO: need test
  151. config.plugins.delete("prefetch"); // TODO: need test
  152. config.resolve.symlinks(true);
  153. // set svg-sprite-loader
  154. config.module
  155. .rule("svg")
  156. .exclude.add(resolve("src/icons"))
  157. .end();
  158. config.module
  159. .rule("icons")
  160. .test(/\.svg$/)
  161. .include.add(resolve("src/icons"))
  162. .end()
  163. .use("svg-sprite-loader")
  164. .loader("svg-sprite-loader")
  165. .options({
  166. symbolId: "icon-[name]"
  167. })
  168. .end();
  169. // set preserveWhitespace
  170. config.module
  171. .rule("vue")
  172. .use("vue-loader")
  173. .loader("vue-loader")
  174. .tap(options => {
  175. // Vue 项目需要添加过滤自定义组件配置。
  176. options.compilerOptions = {
  177. ...options.compilerOptions,
  178. isCustomElement: tag => {
  179. return (
  180. ["conversation-list", "message-list", "message-editor"].indexOf(
  181. tag
  182. ) !== -1
  183. );
  184. }
  185. };
  186. options.compilerOptions.preserveWhitespace = true;
  187. return options;
  188. })
  189. .end();
  190. config
  191. // https://webpack.js.org/configuration/devtool/#development
  192. .when(process.env.NODE_ENV === "development", config =>
  193. config.devtool("cheap-source-map")
  194. );
  195. config.when(process.env.NODE_ENV !== "development", config => {
  196. config
  197. .plugin("ScriptExtHtmlWebpackPlugin")
  198. .after("html")
  199. .use("script-ext-html-webpack-plugin", [
  200. {
  201. // `runtime` must same as runtimeChunk name. default is `runtime`
  202. inline: /runtime\..*\.js$/
  203. }
  204. ])
  205. .end();
  206. config.optimization.splitChunks({
  207. chunks: "all",
  208. cacheGroups: {
  209. libs: {
  210. name: "chunk-libs",
  211. test: /[\\/]node_modules[\\/]/,
  212. priority: 10,
  213. chunks: "initial" // only package third parties that are initially dependent
  214. },
  215. elementUI: {
  216. name: "chunk-elementUI", // split elementUI into a single package
  217. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  218. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  219. },
  220. commons: {
  221. name: "chunk-commons",
  222. test: resolve("src/components"), // can customize your rules
  223. minChunks: 3, // minimum common number
  224. priority: 5,
  225. reuseExistingChunk: true
  226. }
  227. }
  228. });
  229. config.optimization.runtimeChunk("single");
  230. });
  231. }
  232. };