Skip to content

Add support for preamble option #64

@xavierfoucrier

Description

@xavierfoucrier

Hi webpack team 👋

I am currently upgrading a project setup to webpack@5 and want to move from optimize-css-assets-webpack-plugin@5.0.4 to css-minimizer-webpack-plugin@1.0.2, but it looks like there is not way to add a simple banner at the top of the emitted CSS asset, so I am unable to put a preamble the same way I was doing this on webpack@4:

optimization: {
  minimizer: [
    new TerserPlugin({
      extractComments: false,
      terserOptions: {
        output: {
          comments: false,
          preamble: preamble, // <-- add preamble to the app.js asset
        },
      },
    }),
  ],
},
plugins: [
  new OptimizeCSSAssetsPlugin({
    cssProcessorPluginOptions: {
      preset: ['default', {
        discardComments: {
          removeAll: true,
        },
      }],
    },
  }),
  new webpack.BannerPlugin({
    raw: true,
    banner: () => {
      return preamble; // <-- add preamble to the app.css asset
    },
  }),
  // ...
]

I guess it's because new CssMinimizerPlugin move into webpack.optimization.minimizer array 🤔
I think it's not a bug, more a feature that is not supported yet.

Feature Proposal

It would be good to have an option to add a banner/preamble at the top of the emitted asset when css-minimizer-webpack-plugin minimization process ends.

Feature Use Case

Same as TerserPlugin with the preamble option: easy to implement and use without any additional plugins.

May be the option should go into CSSNano.. not sure about that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions