webpack: BannerPlugin does not honor raw

Bug report

What is the current behavior?

A string value for banner that is a JS comment does not appear to work with raw: true.

For example, if I specify the following for a .css file that is generated by webpack:

BannerPlugin({banner: '/* hello world */', raw: true})

I would expect /* hello world */ to get prepended to my file.

Instead, nothing is prepended.

Yes, I know that I could do:

BannerPlugin({banner: 'hello world, raw: true})

but that would produce:

/*! hello world */

which is not what I want. I am at the mercy of other tooling that expects the start of the file to be in a very specific format.

If the current behavior is a bug, please provide the steps to reproduce.

See above.

What is the expected behavior?

The content of my banner string should have nothing to do with raw: true doing what it says it should do.

Other relevant information: webpack version: 5.70.0 Node.js version: v14.14.0 Operating System: macOS Monterey, v12.2.1 Additional tools: I am using a webpack config generated by create-react-app, though with heavy use of rewire to add customizations, such as including BannerPlugin in the optimization.minimizer list.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 21 (16 by maintainers)

Most upvoted comments

Please use:

 new TerserPlugin({
        terserOptions: {
          format: {
            comments: /@bun/i,
          },
        },
        extractComments: false,
      }),

The original problem was resolved, I want to close in favor https://github.com/webpack-contrib/css-minimizer-webpack-plugin/issues/64 and allow to set stage, will implement soon