vue.config.js 6.2 KB

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