| | |
| | | const Compilation = require("./Compilation"); |
| | | const ModuleFilenameHelpers = require("./ModuleFilenameHelpers"); |
| | | const Template = require("./Template"); |
| | | const createSchemaValidation = require("./util/create-schema-validation"); |
| | | |
| | | /** @typedef {import("../declarations/plugins/BannerPlugin").BannerFunction} BannerFunction */ |
| | | /** @typedef {import("webpack-sources").Source} Source */ |
| | | /** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginArgument} BannerPluginArgument */ |
| | | /** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginOptions} BannerPluginOptions */ |
| | | /** @typedef {import("./Compilation").PathData} PathData */ |
| | | /** @typedef {import("./Compiler")} Compiler */ |
| | | /** @typedef {import("./Chunk")} Chunk */ |
| | | /** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */ |
| | | |
| | | const validate = createSchemaValidation( |
| | | /** @type {((value: typeof import("../schemas/plugins/BannerPlugin.json")) => boolean)} */ |
| | | (require("../schemas/plugins/BannerPlugin.check")), |
| | | () => require("../schemas/plugins/BannerPlugin.json"), |
| | | { |
| | | name: "Banner Plugin", |
| | | baseDataPath: "options" |
| | | } |
| | | ); |
| | | /** @typedef {(data: { hash?: string, chunk: Chunk, filename: string }) => string} BannerFunction */ |
| | | |
| | | /** |
| | | * Wraps banner text in a JavaScript block comment, preserving multi-line |
| | | * formatting and escaping accidental comment terminators. |
| | | * @param {string} str string to wrap |
| | | * @returns {string} wrapped string |
| | | */ |
| | |
| | | |
| | | const PLUGIN_NAME = "BannerPlugin"; |
| | | |
| | | /** |
| | | * Prepends or appends banner text to emitted assets that match the configured |
| | | * file filters. |
| | | */ |
| | | class BannerPlugin { |
| | | /** |
| | | * Normalizes banner options and compiles the configured banner source into a |
| | | * function that can render per-asset banner text. |
| | | * @param {BannerPluginArgument} options options object |
| | | */ |
| | | constructor(options) { |
| | |
| | | }; |
| | | } |
| | | |
| | | validate(options); |
| | | |
| | | /** @type {BannerPluginOptions} */ |
| | | this.options = options; |
| | | |
| | | const bannerOption = options.banner; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Apply the plugin |
| | | * Validates the configured options and injects rendered banner comments into |
| | | * matching compilation assets at the configured process-assets stage. |
| | | * @param {Compiler} compiler the compiler instance |
| | | * @returns {void} |
| | | */ |
| | | apply(compiler) { |
| | | compiler.hooks.validate.tap(PLUGIN_NAME, () => { |
| | | compiler.validate( |
| | | () => require("../schemas/plugins/BannerPlugin.json"), |
| | | this.options, |
| | | { |
| | | name: "Banner Plugin", |
| | | baseDataPath: "options" |
| | | }, |
| | | (options) => require("../schemas/plugins/BannerPlugin.check")(options) |
| | | ); |
| | | }); |
| | | const options = this.options; |
| | | const banner = this.banner; |
| | | const matchObject = ModuleFilenameHelpers.matchObject.bind( |
| | | undefined, |
| | | options |
| | | ); |
| | | /** @type {WeakMap<Source, { source: ConcatSource, comment: string }>} */ |
| | | const cache = new WeakMap(); |
| | | const stage = |
| | | this.options.stage || Compilation.PROCESS_ASSETS_STAGE_ADDITIONS; |