webpack.config.prod.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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: '../dist/styles',
  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. ],
  37. },
  38. {
  39. loader: 'file-loader',
  40. options: {
  41. outputPath: path.resolve(projectPath, 'dist/images'),
  42. },
  43. },
  44. ],
  45. },
  46. plugins: [
  47. new MiniCssExtractPlugin({
  48. filename: '[name].css',
  49. chunkFilename: '[id].css',
  50. }),
  51. new HtmlWebpackPlugin({
  52. title: 'Datepicker',
  53. filename: 'index.html',
  54. template: path.resolve(projectPath, 'index.html'),
  55. inject: false,
  56. }),
  57. ],
  58. }