vue.config.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. const fs = require('fs')
  2. const path = require('path')
  3. const webpack = require('webpack')
  4. const {
  5. version,
  6. isProd,
  7. logger,
  8. features
  9. } = require('./feature')
  10. const port = process.env.port || 9527
  11. const copyFiles = [
  12. { file: 'mediainfo.min.js', from: resolveNodeDir('mediainfo.js/dist'), to: '.' },
  13. { file: 'MediaInfoModule.wasm', from: resolveNodeDir('mediainfo.js/dist'), to: '.' },
  14. { file: 'spark-md5.min.js', from: resolveNodeDir('spark-md5'), to: '.' },
  15. { from: resolve(`platform/logo/${process.env.PLATFORM}.png`), to: './logo.png' },
  16. { from: resolve(`platform/fav/${process.env.PLATFORM}.ico`), to: './favicon.ico' }
  17. ]
  18. function resolve (...dir) {
  19. return path.resolve(__dirname, ...dir)
  20. }
  21. function resolveNodeDir (...dir) {
  22. return resolve('node_modules', ...dir)
  23. }
  24. function getCopyFiles () {
  25. return copyFiles
  26. .filter(({ file }) => !file || !fs.existsSync(resolve('public', file)))
  27. .map(({ file, from, to }) => {
  28. return { from: file ? path.join(from, file) : from, to }
  29. })
  30. }
  31. module.exports = {
  32. publicPath: '/admin',
  33. outputDir: `dist/msr_${process.env.ENV}_${version}`,
  34. assetsDir: '',
  35. lintOnSave: !isProd,
  36. productionSourceMap: false,
  37. // devServer: {
  38. // port,
  39. // open: false,
  40. // overlay: {
  41. // warnings: false,
  42. // errors: true
  43. // },
  44. // before: require('./mock/mock-server.js'),
  45. // staticOptions: {
  46. // redirect: true
  47. // }
  48. // },
  49. devServer: {
  50. port,
  51. open: true,
  52. proxy: {
  53. [process.env.VUE_APP_BASE_API]: {
  54. // target: `http://172.31.33.2:20001`,
  55. target: `https://imedia.inspuriit.com`,
  56. changeOrigin: true
  57. },
  58. [process.env.VUE_APP_MINIO]: {
  59. target: `https://imedia.inspuriit.com`,
  60. changeOrigin: true
  61. }
  62. }
  63. // disableHostCheck: true
  64. },
  65. configureWebpack: {
  66. // provide the app's title in webpack's name field, so that
  67. // it can be accessed in index.html to inject the correct title.
  68. name: process.env.VUE_APP_NAME,
  69. resolve: {
  70. alias: {
  71. '@': resolve('src')
  72. }
  73. },
  74. performance: {
  75. maxAssetSize: 5 * 1024 * 1024,
  76. maxEntrypointSize: 2 * 1024 * 1024
  77. }
  78. },
  79. chainWebpack (config) {
  80. // it can improve the speed of the first screen, it is recommended to turn on preload
  81. config.plugin('preload').tap(() => [
  82. {
  83. rel: 'preload',
  84. // to ignore runtime.js
  85. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  86. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  87. include: 'initial'
  88. }
  89. ])
  90. // when there are many pages, it will cause too many meaningless requests
  91. config.plugins.delete('prefetch')
  92. config.plugin('feature-flags')
  93. .use(webpack.DefinePlugin, [features])
  94. // set svg-sprite-loader
  95. config.module
  96. .rule('svg')
  97. .exclude.add(resolve('src/icons'))
  98. .end()
  99. config.module
  100. .rule('icons')
  101. .test(/\.svg$/)
  102. .include.add(resolve('src/icons'))
  103. .end()
  104. .use('svg-sprite-loader')
  105. .loader('svg-sprite-loader')
  106. .options({
  107. symbolId: 'icon-[name]'
  108. })
  109. .end()
  110. config.plugin('copy')
  111. .tap(args => {
  112. const [patterns, ...oArgs] = args
  113. return [
  114. [
  115. ...patterns,
  116. ...getCopyFiles()
  117. ],
  118. ...oArgs
  119. ]
  120. })
  121. config
  122. .when(isProd, config => {
  123. config
  124. .plugin('ScriptExtHtmlWebpackPlugin')
  125. .after('html')
  126. .use('script-ext-html-webpack-plugin', [{
  127. // `runtime` must same as runtimeChunk name. default is `runtime`
  128. inline: /runtime\..*\.js$/
  129. }])
  130. .end()
  131. // config
  132. // .plugin('BundleAnalyzerPlugin')
  133. // .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  134. config
  135. .optimization.splitChunks({
  136. chunks: 'all',
  137. cacheGroups: {
  138. libs: {
  139. name: 'chunk-libs',
  140. test: /[\\/]node_modules[\\/]/,
  141. priority: 10,
  142. chunks: 'initial' // only package third parties that are initially dependent
  143. },
  144. elementUI: {
  145. name: 'chunk-elementUI', // split elementUI into a single package
  146. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  147. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  148. },
  149. commons: {
  150. name: 'chunk-commons',
  151. test: resolve('src/components'), // can customize your rules
  152. minChunks: 3, // minimum common number
  153. priority: 5,
  154. reuseExistingChunk: true
  155. }
  156. }
  157. })
  158. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  159. config
  160. .optimization.runtimeChunk('single')
  161. config
  162. .optimization.minimizer('terser').tap(args => {
  163. // clear console.x
  164. args[0].terserOptions.compress.drop_console = !logger
  165. return args
  166. })
  167. })
  168. },
  169. css: {
  170. loaderOptions: {
  171. scss: {
  172. prependData: `
  173. @import '~@/scss/helpers/index';
  174. `
  175. }
  176. }
  177. }
  178. }