vue.config.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. "use strict";
  2. const path = require("path");
  3. const defaultSettings = require("./src/settings.js");
  4. // ckeditor5
  5. const CKEditorWebpackPlugin = require('@ckeditor/ckeditor5-dev-webpack-plugin')
  6. const { styles } = require('@ckeditor/ckeditor5-dev-utils')
  7. const plugins = [
  8. new CKEditorWebpackPlugin({
  9. language: 'zh-cn',
  10. translationsOutputFile: /app/,
  11. addMainLanguageTranslationsToAllAssets: true,
  12. buildAllTranslationsToSeparateFiles: true
  13. })
  14. ]
  15. function resolve(dir) {
  16. return path.join(__dirname, dir);
  17. }
  18. const name = defaultSettings.title || "小艾协同管理平台"; // page title
  19. // If your port is set to 80,
  20. // use administrator privileges to execute the command line.
  21. // For example, Mac: sudo npm run
  22. const ip = "0.0.0.0"; // dev port
  23. const port = 9528; // dev port
  24. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  25. module.exports = {
  26. // ckeditor5
  27. transpileDependencies: [
  28. /ckeditor5-[^/\\]+[/\\]src[/\\].+\.js$/
  29. ],
  30. /**
  31. * You will need to set publicPath if you plan to deploy your site under a sub path,
  32. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  33. * then publicPath should be set to "/bar/".
  34. * In most cases please use '/' !!!
  35. * Detail: https://cli.vuejs.org/config/#publicpath
  36. */
  37. publicPath: "/settleDown/",
  38. outputDir: "dist",
  39. assetsDir: "static",
  40. lintOnSave: process.env.NODE_ENV === "development",
  41. productionSourceMap: false,
  42. devServer: {
  43. open: true,
  44. host: ip,
  45. port: port,
  46. https: false,
  47. disableHostCheck: true,
  48. // 以上的ip和端口是我们本机的;下面为需要跨域的
  49. proxy: {
  50. // 配置跨域
  51. "/webServer": {
  52. target: 'http://localhost:9001',
  53. ws: true,
  54. changOrigin: true, // 允许跨域
  55. pathRewrite: {
  56. "^/webServer": "" // 请求的时候使用这个server就可以
  57. }
  58. }
  59. }
  60. },
  61. configureWebpack: {
  62. // provide the app's title in webpack's name field, so that
  63. // it can be accessed in index.html to inject the correct title.
  64. name: name,
  65. resolve: {
  66. alias: {
  67. "@": resolve("src")
  68. }
  69. },
  70. plugins
  71. // externals: {
  72. // 'vue': 'Vue',
  73. // 'vue-router': 'VueRouter',
  74. // 'axios': 'axios',
  75. // 'element-ui': 'ELEMENT',
  76. // 'qs': 'Qs',
  77. // 'xlsx': 'XLSX'
  78. // }
  79. },
  80. chainWebpack(config) {
  81. config.plugins.delete("preload"); // TODO: need test
  82. config.plugins.delete("prefetch"); // TODO: need test
  83. // set svg-sprite-loader
  84. config.module
  85. .rule("svg")
  86. .exclude.add(resolve("src/icons"))
  87. .end();
  88. config.module
  89. .rule("icons")
  90. .test(/\.svg$/)
  91. .include.add(resolve("src/icons"))
  92. .end()
  93. .use("svg-sprite-loader")
  94. .loader("svg-sprite-loader")
  95. .options({
  96. symbolId: "icon-[name]"
  97. })
  98. .end();
  99. // set preserveWhitespace
  100. config.module
  101. .rule("vue")
  102. .use("vue-loader")
  103. .loader("vue-loader")
  104. .tap(options => {
  105. options.compilerOptions.preserveWhitespace = true;
  106. return options;
  107. })
  108. .end();
  109. config
  110. // https://webpack.js.org/configuration/devtool/#development
  111. .when(process.env.NODE_ENV === "development", config =>
  112. config.devtool("cheap-source-map")
  113. );
  114. config.when(process.env.NODE_ENV !== "development", config => {
  115. config
  116. .plugin("ScriptExtHtmlWebpackPlugin")
  117. .after("html")
  118. .use("script-ext-html-webpack-plugin", [
  119. {
  120. // `runtime` must same as runtimeChunk name. default is `runtime`
  121. inline: /runtime\..*\.js$/
  122. }
  123. ])
  124. .end();
  125. config.optimization.splitChunks({
  126. chunks: "all",
  127. cacheGroups: {
  128. libs: {
  129. name: "chunk-libs",
  130. test: /[\\/]node_modules[\\/]/,
  131. priority: 10,
  132. chunks: "initial" // only package third parties that are initially dependent
  133. },
  134. elementUI: {
  135. name: "chunk-elementUI", // split elementUI into a single package
  136. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  137. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  138. },
  139. commons: {
  140. name: "chunk-commons",
  141. test: resolve("src/components"), // can customize your rules
  142. minChunks: 3, // minimum common number
  143. priority: 5,
  144. reuseExistingChunk: true
  145. }
  146. }
  147. });
  148. config.optimization.runtimeChunk("single");
  149. });
  150. // ckeditor5
  151. const svgRule = config.module.rule('svg')
  152. svgRule.exclude.add(path.join(__dirname, 'node_modules', '@ckeditor'))
  153. config.module
  154. .rule('cke-svg')
  155. .test(/ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/)
  156. .use('raw-loader')
  157. .loader('raw-loader')
  158. config.module
  159. .rule('cke-css')
  160. .test(/ckeditor5-[^/\\]+[/\\].+\.css$/)
  161. .use('postcss-loader')
  162. .loader('postcss-loader')
  163. .tap(() => {
  164. return styles.getPostCssConfig({
  165. themeImporter: {
  166. themePath: require.resolve('@ckeditor/ckeditor5-theme-lark')
  167. },
  168. minify: true
  169. })
  170. })
  171. }
  172. };