webpack.config.prod.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. const path = require('path');
  2. const CopyWebpackPlugin = require('copy-webpack-plugin');
  3. // const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
  4. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  5. module.exports = {
  6. mode: 'production',
  7. entry: path.resolve(__dirname, 'src'),
  8. output: {
  9. path: path.resolve(__dirname, 'build'),
  10. filename: 'webviewer-ui.min.js',
  11. chunkFilename: 'chunks/[name].chunk.js',
  12. publicPath: './',
  13. },
  14. plugins: [
  15. new CopyWebpackPlugin([
  16. {
  17. from: './src/index.core.html',
  18. to: '../build/index.html',
  19. },
  20. {
  21. from: './i18n',
  22. to: '../build/i18n',
  23. },
  24. {
  25. from: './assets',
  26. to: '../build/assets',
  27. ignore: ['icons/*.svg'],
  28. },
  29. {
  30. from: './src/configorigin.txt',
  31. to: '../build/configorigin.txt',
  32. },
  33. ]),
  34. new MiniCssExtractPlugin({
  35. filename: 'style.css',
  36. chunkFilename: 'chunks/[name].chunk.css'
  37. }),
  38. // new BundleAnalyzerPlugin()
  39. ],
  40. module: {
  41. rules: [
  42. {
  43. test: /\.js$/,
  44. use: {
  45. loader: 'babel-loader',
  46. options: {
  47. presets: [
  48. '@babel/preset-react',
  49. [
  50. '@babel/preset-env',
  51. {
  52. useBuiltIns: 'entry',
  53. corejs: 3,
  54. },
  55. ],
  56. ],
  57. plugins: [
  58. '@babel/plugin-proposal-function-sent',
  59. '@babel/plugin-proposal-export-namespace-from',
  60. '@babel/plugin-proposal-numeric-separator',
  61. '@babel/plugin-proposal-throw-expressions',
  62. '@babel/plugin-proposal-class-properties',
  63. '@babel/plugin-proposal-optional-chaining',
  64. ],
  65. },
  66. },
  67. include: [path.resolve(__dirname, 'src'), path.resolve(__dirname, 'node_modules')],
  68. exclude: function(modulePath) {
  69. return /node_modules/.test(modulePath) && !/node_modules.+react-dnd/.test(modulePath);
  70. }
  71. },
  72. {
  73. test: /\.scss$/,
  74. use: [
  75. MiniCssExtractPlugin.loader,
  76. 'css-loader',
  77. {
  78. loader: 'postcss-loader',
  79. options: {
  80. ident: 'postcss',
  81. plugins: loader => [
  82. require('postcss-import')({ root: loader.resourcePath }),
  83. require('postcss-preset-env')(),
  84. require('cssnano')(),
  85. ],
  86. },
  87. },
  88. 'sass-loader',
  89. ],
  90. include: path.resolve(__dirname, 'src'),
  91. },
  92. {
  93. test: /\.svg$/,
  94. use: ['svg-inline-loader'],
  95. },
  96. {
  97. test: /\.woff(2)?$/,
  98. use: [
  99. {
  100. loader: 'file-loader',
  101. options: {
  102. name: '[name].[ext]',
  103. // this is used to overwrite the publicPath that is specified in the output object,
  104. // to make the url of the fonts be relative to the minified style.css
  105. publicPath: './assets/fonts',
  106. outputPath: '/assets/fonts',
  107. },
  108. },
  109. ],
  110. },
  111. ],
  112. },
  113. resolve: {
  114. alias: {
  115. src: path.resolve(__dirname, 'src/'),
  116. components: path.resolve(__dirname, 'src/components/'),
  117. constants: path.resolve(__dirname, 'src/constants/'),
  118. helpers: path.resolve(__dirname, 'src/helpers/'),
  119. hooks: path.resolve(__dirname, 'src/hooks/'),
  120. actions: path.resolve(__dirname, 'src/redux/actions/'),
  121. reducers: path.resolve(__dirname, 'src/redux/reducers/'),
  122. selectors: path.resolve(__dirname, 'src/redux/selectors/'),
  123. core: path.resolve(__dirname, 'src/core/'),
  124. },
  125. },
  126. optimization: {
  127. splitChunks: {
  128. automaticNameDelimiter: '.',
  129. minSize: 0,
  130. },
  131. },
  132. devtool: 'source-map',
  133. };