The names of bundled files can be added to the divider comment by using a build tool or bundler that allows for specifying a comment string format. Typically, this is done by including a placeholder in the comment string that will be replaced with the bundle filename or a list of filenames. For example, in Webpack, the comment string format can be set using the banner
plugin option, which allows for placeholders such as [name]
or [file]
to be used.
Here is an example using Webpack:
const webpack = require('webpack');
const config = {
// configure entry and output options
entry: './src/index.js',
output: {
filename: 'bundle.js',
},
// configure plugins
plugins: [
new webpack.BannerPlugin({
banner: `/*\nBundle: [file]\n*/`,
raw: true,
entryOnly: true,
}),
],
};
module.exports = config;
In this example, the BannerPlugin
is used to add a banner comment to the bundled file. The banner
option specifies the comment string format, which includes the [file]
placeholder. When Webpack bundles the files, it will replace this placeholder with the name of the bundled file. The output will include a comment at the top of the file that looks like this:
/*
Bundle: bundle.js
*/
Asked: 2023-07-14 16:08:09 +0000
Seen: 7 times
Last updated: Jul 14 '23