22

I'm using webpack to bundle a bunch of javascript files together, and I need to include a copyright notice at the top of the file. I can't seem to figure out how to do that, or if it is possible.

The closest I've come is to use the raw loader, but that hides the copyright in an exported function. Any idea.

Something that is cross-platform is preferred.

pedalpete
  • 21,076
  • 45
  • 128
  • 239

1 Answers1

34

You can use the webpack BannerPlugin. With this plugin you can add any string you want at the top of your bundled file.

I have used it to add some package name, version, license, and other info at the top of a library of my own.

webpack.config.js

module.exports = {
  // Other stuff
  plugins: [
    new webpack.BannerPlugin('Your copyright notice')
  ]
};
Jonny
  • 2,223
  • 23
  • 30
dreyescat
  • 13,558
  • 5
  • 50
  • 38
  • updated link: https://webpack.js.org/plugins/banner-plugin/#root – adamellsworth Dec 10 '20 at 20:05
  • 5
    The BannerPlugin doesn't work in production mode if you're adding raw comments, like in a UserScript. Instead, it adds `/*! For license information please see .min.user.js.LICENSE.txt */`. – Nato Boram Oct 31 '21 at 00:04
  • I was able to manually add a comment both at the end and at the beginning of my bundle file using the technique outlined here: https://github.com/webpack/webpack-cli/issues/312#issuecomment-732749280 – Fearnbuster Jan 13 '22 at 21:18