MiniCssExtractPlugin不使用webpack缩小css代码

gxwragnw  于 2023-11-19  发布在  Webpack
关注(0)|答案(1)|浏览(171)

Webpack版本:4.35.3
所有的编译都是成功的。我的代码在编译后在weble.css中没有缩小。我试图在text-webpack-plugin中使用minimize:true,但它不起作用。
对于编译,我在命令行中使用命令:webpack在我的工作目录中
我做错了什么?为什么MiniCssExtractPlugin不工作,也许是因为resolve-url-loader?
我的wepback配置:

  1. const AssetsWebpackPlugin = require('assets-webpack-plugin')
  2. const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  3. const FaviconsWebpackPlugin = require('favicons-webpack-plugin')
  4. const FileManagerPlugin = require('filemanager-webpack-plugin')
  5. const { PATH } = require('../constants')
  6. module.exports = {
  7. mode: 'production',
  8. output: {
  9. path: PATH.publicFolder,
  10. publicPath: '/',
  11. filename: 'static/react/js/[name].[contenthash].js',
  12. chunkFilename: 'static/react/js/[name].[contenthash].js',
  13. sourceMapFilename: 'static/react/js/[name].[contenthash].js.map',
  14. jsonpFunction: 'reactJsonpFunction',
  15. },
  16. performance: {
  17. hints: false,
  18. },
  19. watch: false,
  20. devtool: 'source-map',
  21. plugins: [
  22. new DefinePlugin({
  23. NODE_ENV: JSON.stringify('production'),
  24. }),
  25. new AssetsWebpackPlugin({
  26. filename: 'static/react/assets.json',
  27. path: PATH.publicFolder,
  28. }),
  29. new MiniCssExtractPlugin({
  30. filename: 'static/react/css/common.css',
  31. }),
  32. new FaviconsWebpackPlugin({
  33. logo: PATH.favicon,
  34. prefix: 'static/react/icons/',
  35. emitStats: false,
  36. statsFilename: 'iconstats.json',
  37. background: '#fff',
  38. persistentCache: true,
  39. inject: true,
  40. icons: {
  41. android: true,
  42. appleIcon: true,
  43. appleStartup: true,
  44. coast: false,
  45. favicons: true,
  46. firefox: true,
  47. opengraph: false,
  48. twitter: false,
  49. yandex: false,
  50. windows: false,
  51. },
  52. }),
  53. new FileManagerPlugin({
  54. onStart: {
  55. delete: ['../jrp-web-app/static/react/'],
  56. },
  57. onEnd: {
  58. mkdir: ['../jrp-web-app/static/react/'],
  59. copy: [
  60. {
  61. source: 'public/static/react',
  62. destination: '../jrp-web-app/static/react',
  63. },
  64. ],
  65. },
  66. }),
  67. ],
  68. module: {
  69. rules: [
  70. {
  71. test: /\.(png|jpg|gif|svg|woff|woff2)$/,
  72. use: [
  73. {
  74. loader: 'file-loader',
  75. options: {
  76. name: 'static/react/images/[name]-[hash:8].[ext]',
  77. },
  78. },
  79. ],
  80. },
  81. {
  82. test: /\.css$/,
  83. use: [
  84. MiniCssExtractPlugin.loader,
  85. {
  86. loader: 'css-loader',
  87. options: {
  88. sourceMap: false,
  89. },
  90. },
  91. 'resolve-url-loader',
  92. {
  93. loader: 'postcss-loader',
  94. options: {
  95. sourceMap: false,
  96. config: {
  97. path: PATH.postcssConfig,
  98. },
  99. },
  100. },
  101. ],
  102. },
  103. ],
  104. },
  105. }```

字符串

xurqigkl

xurqigkl1#

你有在js文件中使用过cssle.css吗?如果没有,mini-css-extract-plugin会忽略它。

相关问题