webpack.config.prod.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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: './src/index.js',
  8. output: {
  9. path: path.resolve(__dirname, '../dist'),
  10. filename: '[name]-bundle-[hash:8].js',
  11. },
  12. module: {
  13. rules: [
  14. {
  15. test: /\.js$/,
  16. loader: 'babel-loader',
  17. exclude: /node_modules/,
  18. },
  19. {
  20. test: /\.css$/,
  21. use: [
  22. {
  23. loader: MiniCssExtractPlugin.loader,
  24. options: {
  25. publicPath: './',
  26. },
  27. },
  28. {
  29. loader: 'css-loader',
  30. options: {
  31. modules: true,
  32. camelCase: true,
  33. localIdentName: '[name]__[local]--[hash:base64:5]',
  34. },
  35. },
  36. 'postcss-loader',
  37. ],
  38. },
  39. {
  40. test: /\.(jpe?g|png|svg|bmp)$/,
  41. loader: 'file-loader',
  42. options: {
  43. outputPath: 'images/',
  44. name: '[name]-[hash:base64:5].[ext]',
  45. },
  46. },
  47. ],
  48. },
  49. plugins: [
  50. new MiniCssExtractPlugin({
  51. filename: '[name].[hash].css',
  52. chunkFilename: '[id].[hash:base64:5].css',
  53. }),
  54. new HtmlWebpackPlugin({
  55. title: 'Datepicker',
  56. filename: 'index.html',
  57. template: path.resolve(projectPath, 'index.html'),
  58. inject: false,
  59. }),
  60. ],
  61. }