* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}
(compiler)
| 61 | * @returns {void} |
| 62 | */ |
| 63 | apply(compiler) { |
| 64 | compiler.hooks.validate.tap(PLUGIN_NAME, () => { |
| 65 | compiler.validate( |
| 66 | () => require("../schemas/plugins/ManifestPlugin.json"), |
| 67 | this.options, |
| 68 | { |
| 69 | name: "ManifestPlugin", |
| 70 | baseDataPath: "options" |
| 71 | }, |
| 72 | (options) => require("../schemas/plugins/ManifestPlugin.check")(options) |
| 73 | ); |
| 74 | }); |
| 75 | |
| 76 | const entrypoints = |
| 77 | this.options.entrypoints !== undefined ? this.options.entrypoints : true; |
| 78 | const serialize = |
| 79 | this.options.serialize || |
| 80 | ((manifest) => JSON.stringify(manifest, null, 2)); |
| 81 | |
| 82 | compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => { |
| 83 | compilation.hooks.processAssets.tap( |
| 84 | { |
| 85 | name: PLUGIN_NAME, |
| 86 | stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE |
| 87 | }, |
| 88 | () => { |
| 89 | const hashDigestLength = compilation.outputOptions.hashDigestLength; |
| 90 | const publicPath = compilation.getPath( |
| 91 | compilation.outputOptions.publicPath |
| 92 | ); |
| 93 | |
| 94 | /** |
| 95 | * Creates a hash reg exp. |
| 96 | * @param {string | string[]} value value |
| 97 | * @returns {RegExp} regexp to remove hash |
| 98 | */ |
| 99 | const createHashRegExp = (value) => |
| 100 | new RegExp( |
| 101 | `(?:\\.${Array.isArray(value) ? `(${value.join("|")})` : value})(?=\\.)`, |
| 102 | "gi" |
| 103 | ); |
| 104 | |
| 105 | /** |
| 106 | * Removes the provided name from the manifest plugin. |
| 107 | * @param {string} name name |
| 108 | * @param {AssetInfo | null} info asset info |
| 109 | * @returns {string} hash removed name |
| 110 | */ |
| 111 | const removeHash = (name, info) => { |
| 112 | // Handles hashes that match configured `hashDigestLength` |
| 113 | // i.e. index.XXXX.html -> index.html (html-webpack-plugin) |
| 114 | if (hashDigestLength <= 0) return name; |
| 115 | const reg = createHashRegExp(`[a-f0-9]{${hashDigestLength},32}`); |
| 116 | return name.replace(reg, ""); |
| 117 | }; |
| 118 | |
| 119 | /** |
| 120 | * Returns chunk name or chunk id. |
nothing calls this directly
no test coverage detected