Skip to content

How to add some banner to the trunks header, such as copy right? #26752

Closed
@Caesar-APAX

Description

@Caesar-APAX

What version of Next.js are you using?

11.0.1

What version of Node.js are you using?

v14.5.0

What browser are you using?

Chrome

What operating system are you using?

macOs

How are you deploying your application?

next build

Describe the Bug

new webpack.BannerPlugin({
   banner: '/**  some text */'
})

But i run the command 'next build', the js and css trunks not see the copyright. I sure the reason cause by webpack5 and next11.

Expected Behavior

Can you tell me how do this?

To Reproduce

const { Compilation, sources } = require('webpack')

class BannerPlugin {
  constructor(options) {
    this.banner = options.banner
  }

  apply(compiler) {
    compiler.hooks.compilation.tap('BannerPlugin', (compilation) => {
      compilation.hooks.processAssets.tap(
        {
          name: 'BannerPlugin',
          stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
        },
        (assets) => {
          Object.entries(assets).forEach(([pathname, source]) => {
            compilation.updateAsset(
              pathname,
              new sources.RawSource(this.banner + source.source())
            )
          })
        }
      )
    })
  }
}

module.exports = BannerPlugin

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions