webpack.dv.babel.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // Important modules this config uses
  2. const path = require('path')
  3. const HtmlWebpackPlugin = require('html-webpack-plugin')
  4. const { HashedModuleIdsPlugin } = require('webpack')
  5. const TerserPlugin = require('terser-webpack-plugin')
  6. const CompressionPlugin = require('compression-webpack-plugin')
  7. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  8. module.exports = require('./webpack.base.babel')({
  9. mode: 'production',
  10. // In production, we skip all hot-reloading stuff
  11. entry: {
  12. app: [
  13. require.resolve('react-app-polyfill/ie11'),
  14. path.join(process.cwd(), 'app/app.tsx')
  15. ],
  16. share: [
  17. require.resolve('react-app-polyfill/ie11'),
  18. path.join(process.cwd(), 'share/app.tsx')
  19. ]
  20. },
  21. // Utilize long-term caching by adding content hashes (not compilation hashes) to compiled assets
  22. output: {
  23. path: path.resolve(process.cwd(), '../davinci-ui'),
  24. filename: '[name].[chunkhash].js',
  25. chunkFilename: '[name].[chunkhash].chunk.js'
  26. },
  27. tsLoaders: [
  28. // {
  29. // loader: 'awesome-typescript-loader',
  30. // options: {
  31. // useBabel: true,
  32. // babelOptions: {
  33. // babelrc: true
  34. // },
  35. // useCache: false
  36. // }
  37. // }
  38. {
  39. loader: 'babel-loader'
  40. },
  41. {
  42. loader: 'ts-loader',
  43. options: {
  44. transpileOnly: true
  45. }
  46. }
  47. ],
  48. optimization: {
  49. minimize: true,
  50. minimizer: [
  51. new TerserPlugin({
  52. terserOptions: {
  53. warnings: false,
  54. compress: {
  55. comparisons: false
  56. },
  57. parse: {},
  58. mangle: true,
  59. output: {
  60. comments: false,
  61. ascii_only: true
  62. }
  63. },
  64. parallel: true,
  65. cache: true,
  66. sourceMap: true
  67. })
  68. ],
  69. nodeEnv: 'production',
  70. sideEffects: true,
  71. concatenateModules: true,
  72. splitChunks: {
  73. chunks: 'all',
  74. minSize: 30000,
  75. minChunks: 1,
  76. maxAsyncRequests: 5,
  77. maxInitialRequests: 3,
  78. name: true,
  79. cacheGroups: {
  80. vendors: {
  81. test: /[\\/]node_modules[\\/](?!antd|jquery|three|bootstrap-datepicker)(.[a-zA-Z0-9.\-_]+)[\\/]/,
  82. // test: /[\\/]node_modules[\\/]/,
  83. name: 'vendor',
  84. chunks: 'all'
  85. }
  86. // main: {
  87. // chunks: 'all',
  88. // minChunks: 2,
  89. // reuseExistingChunk: true,
  90. // enforce: true
  91. // }
  92. }
  93. },
  94. runtimeChunk: true
  95. },
  96. plugins: [
  97. // Minify and optimize the index.html
  98. new HtmlWebpackPlugin({
  99. filename: 'index.html',
  100. chunks: ['app', 'runtime~app', 'app~share', 'vendor'],
  101. template: 'app/index.html',
  102. minify: {
  103. removeComments: true,
  104. collapseWhitespace: true,
  105. removeRedundantAttributes: true,
  106. useShortDoctype: true,
  107. removeEmptyAttributes: true,
  108. removeStyleLinkTypeAttributes: true,
  109. keepClosingSlash: true,
  110. minifyJS: true,
  111. minifyCSS: true,
  112. minifyURLs: true
  113. },
  114. inject: true
  115. }),
  116. new HtmlWebpackPlugin({
  117. filename: 'share.html',
  118. chunks: ['share', 'runtime~share', 'app~share', 'vendor'],
  119. template: 'app/index.html',
  120. minify: {
  121. removeComments: true,
  122. collapseWhitespace: true,
  123. removeRedundantAttributes: true,
  124. useShortDoctype: true,
  125. removeEmptyAttributes: true,
  126. removeStyleLinkTypeAttributes: true,
  127. keepClosingSlash: true,
  128. minifyJS: true,
  129. minifyCSS: true,
  130. minifyURLs: true
  131. },
  132. inject: true
  133. }),
  134. new CompressionPlugin({
  135. algorithm: 'gzip',
  136. test: /\.js$|\.css$|\.html$/,
  137. threshold: 10240,
  138. minRatio: 0.8
  139. }),
  140. new HashedModuleIdsPlugin({
  141. hashFunction: 'sha256',
  142. hashDigest: 'hex',
  143. hashDigestLength: 20
  144. }),
  145. new BundleAnalyzerPlugin({
  146. analyzerMode: 'server',
  147. analyzerHost: 'localhost',
  148. analyzerPort: 5000,
  149. reportFilename: 'report.html',
  150. defaultSizes: 'parsed',
  151. openAnalyzer: true,
  152. generateStatsFile: true,
  153. statsFilename: '../stats.json',
  154. statsOptions: null,
  155. logLevel: 'info'
  156. })
  157. ],
  158. performance: {
  159. assetFilter: assetFilename =>
  160. !/(\.map$)|(^(main\.|favicon\.))/.test(assetFilename)
  161. },
  162. htmlWebpackPlugin: {
  163. files: {
  164. js: ['app.js', 'share.js'],
  165. chunks: {
  166. app: {
  167. entry: 'app.js'
  168. },
  169. share: {
  170. entry: 'share.js'
  171. }
  172. }
  173. }
  174. }
  175. })