vue.config.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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: "/lifeline/",
  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://47.113.200.81:9005/',
  53. // target: "http://lifeline.idea-sf.com/lifelineApi", // 测试服
  54. // target: "http://2.21.138.147:8080/api",
  55. target: 'http://localhost:9001',
  56. ws: true,
  57. changOrigin: true, // 允许跨域
  58. pathRewrite: {
  59. "^/webServer": "" // 请求的时候使用这个server就可以
  60. }
  61. }
  62. }
  63. },
  64. configureWebpack: {
  65. // provide the app's title in webpack's name field, so that
  66. // it can be accessed in index.html to inject the correct title.
  67. name: name,
  68. resolve: {
  69. alias: {
  70. "@": resolve("src")
  71. }
  72. },
  73. plugins
  74. // externals: {
  75. // 'vue': 'Vue',
  76. // 'vue-router': 'VueRouter',
  77. // 'axios': 'axios',
  78. // 'element-ui': 'ELEMENT',
  79. // 'qs': 'Qs',
  80. // 'xlsx': 'XLSX'
  81. // }
  82. },
  83. chainWebpack(config) {
  84. config.plugins.delete("preload"); // TODO: need test
  85. config.plugins.delete("prefetch"); // TODO: need test
  86. // set svg-sprite-loader
  87. config.module
  88. .rule("svg")
  89. .exclude.add(resolve("src/icons"))
  90. .end();
  91. config.module
  92. .rule("icons")
  93. .test(/\.svg$/)
  94. .include.add(resolve("src/icons"))
  95. .end()
  96. .use("svg-sprite-loader")
  97. .loader("svg-sprite-loader")
  98. .options({
  99. symbolId: "icon-[name]"
  100. })
  101. .end();
  102. // set preserveWhitespace
  103. config.module
  104. .rule("vue")
  105. .use("vue-loader")
  106. .loader("vue-loader")
  107. .tap(options => {
  108. options.compilerOptions.preserveWhitespace = true;
  109. return options;
  110. })
  111. .end();
  112. config
  113. // https://webpack.js.org/configuration/devtool/#development
  114. .when(process.env.NODE_ENV === "development", config =>
  115. config.devtool("cheap-source-map")
  116. );
  117. config.when(process.env.NODE_ENV !== "development", config => {
  118. config
  119. .plugin("ScriptExtHtmlWebpackPlugin")
  120. .after("html")
  121. .use("script-ext-html-webpack-plugin", [
  122. {
  123. // `runtime` must same as runtimeChunk name. default is `runtime`
  124. inline: /runtime\..*\.js$/
  125. }
  126. ])
  127. .end();
  128. config.optimization.splitChunks({
  129. chunks: "all",
  130. cacheGroups: {
  131. libs: {
  132. name: "chunk-libs",
  133. test: /[\\/]node_modules[\\/]/,
  134. priority: 10,
  135. chunks: "initial" // only package third parties that are initially dependent
  136. },
  137. elementUI: {
  138. name: "chunk-elementUI", // split elementUI into a single package
  139. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  140. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  141. },
  142. commons: {
  143. name: "chunk-commons",
  144. test: resolve("src/components"), // can customize your rules
  145. minChunks: 3, // minimum common number
  146. priority: 5,
  147. reuseExistingChunk: true
  148. }
  149. }
  150. });
  151. config.optimization.runtimeChunk("single");
  152. });
  153. // ckeditor5
  154. const svgRule = config.module.rule('svg')
  155. svgRule.exclude.add(path.join(__dirname, 'node_modules', '@ckeditor'))
  156. config.module
  157. .rule('cke-svg')
  158. .test(/ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/)
  159. .use('raw-loader')
  160. .loader('raw-loader')
  161. config.module
  162. .rule('cke-css')
  163. .test(/ckeditor5-[^/\\]+[/\\].+\.css$/)
  164. .use('postcss-loader')
  165. .loader('postcss-loader')
  166. .tap(() => {
  167. return styles.getPostCssConfig({
  168. themeImporter: {
  169. themePath: require.resolve('@ckeditor/ckeditor5-theme-lark')
  170. },
  171. minify: true
  172. })
  173. })
  174. }
  175. };