vue.config.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. "use strict";
  2. const path = require("path");
  3. const defaultSettings = require("./src/settings.js");
  4. const webpack = require("webpack");
  5. function resolve(dir) {
  6. return path.join(__dirname, dir);
  7. }
  8. const name = defaultSettings.title || "zxkcadmin"; // page title
  9. // If your port is set to 80,
  10. // use administrator privileges to execute the command line.
  11. // For example, Mac: sudo npm run
  12. // You can change the port by the following methods:
  13. // port = 9528 npm run dev OR npm run dev --port = 9528
  14. const port = process.env.port || process.env.npm_config_port || 7000; // dev port
  15. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  16. module.exports = {
  17. /**
  18. * You will need to set publicPath if you plan to deploy your site under a sub path,
  19. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  20. * then publicPath should be set to "/bar/".
  21. * In most cases please use '/' !!!
  22. * Detail: https://cli.vuejs.org/config/#publicpath
  23. */
  24. publicPath: "/",
  25. outputDir: "dist",
  26. assetsDir: "static",
  27. lintOnSave: false, //process.env.NODE_ENV === 'development'
  28. productionSourceMap: false,
  29. devServer: {
  30. disableHostCheck: true,
  31. port: port,
  32. open: false,
  33. headers: {
  34. "Access-Control-Allow-Origin": "*"
  35. },
  36. overlay: {
  37. warnings: false,
  38. errors: true
  39. },
  40. proxy: {
  41. // change xxx-api/login => mock/login
  42. // detail: https://cli.vuejs.org/config/#devserver-proxy
  43. [process.env.VUE_APP_BASE_API]: {
  44. target: `http://192.168.0.246:8602`,
  45. // target: `http://192.168.0.56:8502`,
  46. // target: `http://192.168.0.248:6000`,
  47. //target: `http://api.szlcloud.com/admin`,
  48. // target:http://a21347410b.iask.in:6000
  49. changeOrigin: true,
  50. logLevel: "debug",
  51. pathRewrite: {
  52. ["^" + process.env.VUE_APP_BASE_API]: ""
  53. }
  54. }
  55. // logLevel: "debug"
  56. }
  57. //after: require('./mock/mock-server.js')
  58. },
  59. configureWebpack: {
  60. // provide the app's title in webpack's name field, so that
  61. // it can be accessed in index.html to inject the correct title.
  62. name: name,
  63. resolve: {
  64. alias: {
  65. "@": resolve("src")
  66. }
  67. }
  68. },
  69. chainWebpack(config) {
  70. config.plugins.delete("preload"); // TODO: need test
  71. config.plugins.delete("prefetch"); // TODO: need test
  72. config.plugin("provide").use(webpack.ProvidePlugin, [
  73. {
  74. "window.Quill": "quill"
  75. }
  76. ]);
  77. // set svg-sprite-loader
  78. config.module
  79. .rule("svg")
  80. .exclude.add(resolve("src/icons"))
  81. .end();
  82. config.module
  83. .rule("icons")
  84. .test(/\.svg$/)
  85. .include.add(resolve("src/icons"))
  86. .end()
  87. .use("svg-sprite-loader")
  88. .loader("svg-sprite-loader")
  89. .options({
  90. symbolId: "icon-[name]"
  91. })
  92. .end();
  93. // set preserveWhitespace
  94. config.module
  95. .rule("vue")
  96. .use("vue-loader")
  97. .loader("vue-loader")
  98. .tap(options => {
  99. options.compilerOptions.preserveWhitespace = true;
  100. return options;
  101. })
  102. .end();
  103. config
  104. // https://webpack.js.org/configuration/devtool/#development
  105. .when(process.env.NODE_ENV === "development", config =>
  106. config.devtool("cheap-source-map")
  107. );
  108. config.when(process.env.NODE_ENV !== "development", config => {
  109. config
  110. .plugin("ScriptExtHtmlWebpackPlugin")
  111. .after("html")
  112. .use("script-ext-html-webpack-plugin", [
  113. {
  114. // `runtime` must same as runtimeChunk name. default is `runtime`
  115. inline: /runtime\..*\.js$/
  116. }
  117. ])
  118. .end();
  119. config.optimization.splitChunks({
  120. chunks: "all",
  121. cacheGroups: {
  122. libs: {
  123. name: "chunk-libs",
  124. test: /[\\/]node_modules[\\/]/,
  125. priority: 10,
  126. chunks: "initial" // only package third parties that are initially dependent
  127. },
  128. elementUI: {
  129. name: "chunk-elementUI", // split elementUI into a single package
  130. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  131. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  132. },
  133. commons: {
  134. name: "chunk-commons",
  135. test: resolve("src/components"), // can customize your rules
  136. minChunks: 3, // minimum common number
  137. priority: 5,
  138. reuseExistingChunk: true
  139. }
  140. }
  141. });
  142. config.optimization.runtimeChunk("single");
  143. });
  144. }
  145. };