Skip to content

Webpack BannerPlugin with raw option should put use strict on the very first line #18202

@anothertempore

Description

@anothertempore

Bug report

What is the current behavior?

  1. When using BannerPlugin with raw option, it appends the code before "use strict", this will cause strict mode to not function properly.
  2. When set minimize to true, TerserPlugin will remove "use strict" in between.

Context: Before #13842, webpack add "use strict" inside each function, so we don't have this issue. But after this, webpack seems like shift all "use strict" to the top, that's the root cause of this issue.

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

Repo to reproduce the bug: https://github.com/anothertempore/webpack-banner-use-strict

Steps:

  1. clone the repo
  2. run pnpm install
  3. run pnpm build, then check dist/async file, "use strict" is not in the very first line, which is incorrect.
  4. change this line to true, then check dist/async, "use strict" will be removed.

What is the expected behavior?

"use strict" statement should always in the very first line.

Other relevant information:
webpack version: 5.90.3
Node.js version: 18
Operating System: MacOS
Additional tools:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions