production.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  2. const HtmlWebpackPlugin = require('html-webpack-plugin');
  3. const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
  4. module.exports = env => ({
  5. devtool: 'source-map',
  6. output: {
  7. filename: '[name].[contenthash].js',
  8. },
  9. optimization: {
  10. moduleIds: 'hashed',
  11. runtimeChunk: 'single',
  12. splitChunks: {
  13. cacheGroups: {
  14. vendor: {
  15. test: /[\\/]node_modules[\\/]/,
  16. name: 'vendors',
  17. chunks: 'all',
  18. },
  19. },
  20. },
  21. },
  22. module: {
  23. rules: [
  24. {
  25. test: /\.css$/,
  26. use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'],
  27. },
  28. {
  29. test: /\.scss$/,
  30. use: [
  31. MiniCssExtractPlugin.loader,
  32. 'css-loader',
  33. 'postcss-loader',
  34. 'sass-loader',
  35. ],
  36. },
  37. ],
  38. },
  39. plugins: [
  40. new HtmlWebpackPlugin({
  41. template: './index.html',
  42. minify: {
  43. collapseWhitespace: true,
  44. removeComments: true,
  45. removeRedundantAttributes: true,
  46. removeScriptTypeAttributes: true,
  47. removeStyleLinkTypeAttributes: true,
  48. useShortDoctype: true,
  49. },
  50. }),
  51. new MiniCssExtractPlugin({
  52. filename: '[name].[contenthash].css',
  53. chunkFilename: '[name].[id].[contenthash].css',
  54. }),
  55. new OptimizeCssAssetsPlugin({}),
  56. ],
  57. });