webpack.config.prod.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const path = require('path')
  2. const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  3. const HtmlWebpackPlugin = require('html-webpack-plugin')
  4. const projectPath = path.resolve(__dirname, '../')
  5. module.exports = {
  6. mode: 'production',
  7. entry: {
  8. index: './src/app.js',
  9. vendor: ['react', 'react-dom', 'prop-types', 'classnames'],
  10. },
  11. output: {
  12. path: path.resolve(__dirname, '../dist'),
  13. filename: '[name]-bundle-[hash:8].js',
  14. },
  15. module: {
  16. rules: [
  17. {
  18. test: /\.js$/,
  19. loader: 'babel-loader',
  20. exclude: /node_modules/,
  21. },
  22. {
  23. test: /\.css$/,
  24. use: [
  25. {
  26. loader: MiniCssExtractPlugin.loader,
  27. options: {
  28. publicPath: './',
  29. },
  30. },
  31. {
  32. loader: 'css-loader',
  33. options: {
  34. modules: true,
  35. camelCase: true,
  36. localIdentName: '[name]__[local]--[hash:base64:5]',
  37. },
  38. },
  39. 'postcss-loader',
  40. ],
  41. },
  42. {
  43. test: /\.(jpe?g|png|svg|bmp)$/,
  44. loader: 'file-loader',
  45. options: {
  46. outputPath: 'images/',
  47. name: '[name]-[hash:base64:5].[ext]',
  48. },
  49. },
  50. ],
  51. },
  52. plugins: [
  53. new MiniCssExtractPlugin({
  54. filename: '[name].[hash].css',
  55. chunkFilename: '[id].[hash].css',
  56. }),
  57. new HtmlWebpackPlugin({
  58. title: 'Datepicker',
  59. filename: 'index.html',
  60. template: path.resolve(projectPath, 'index.html'),
  61. inject: false,
  62. }),
  63. ],
  64. }