vue.config.js 6.5 KB

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