From d29395b57430ff51553511d3ff992f0e9002939a Mon Sep 17 00:00:00 2001 From: Steel Fu Date: Fri, 25 Sep 2020 12:46:13 -0700 Subject: [PATCH 1/2] allow filtering which file to inject manifest into --- README.md | 2 ++ package.json | 1 + src/generators/tapable.js | 7 ++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ead69f1..a28d68d 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,8 @@ Presets of `options`: } ``` +`inject` accepts a boolean or function to allow filtering the file to inject into. e.g. `(htmlPlugin) => basename(htmlPlugin.options.filename) === 'index.html'` + By default, HTML injection and fingerprint generation are on. With `inject: false` and `fingerprints: false`, respectively, you can turn them off. diff --git a/package.json b/package.json index d49d1a6..216df5d 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ ], "scripts": { "build": "npx babel src --out-dir dist", + "prepare": "npm run build", "clean": "rimraf -rf tests/*/output && rimraf -rf dist", "test": "npm run clean && npm run build && node tests/index.js", "test:debug": "npm run clean && npm run build && node --inspect-brk ./tests/index.js" diff --git a/src/generators/tapable.js b/src/generators/tapable.js index 58c240c..cb70438 100644 --- a/src/generators/tapable.js +++ b/src/generators/tapable.js @@ -22,7 +22,12 @@ module.exports = function (that, { hooks: { compilation: comp, emit } }) { beforeProcessingHook.tapAsync('webpack-pwa-manifest', function(htmlPluginData, callback) { if (!that.htmlPlugin) that.htmlPlugin = true buildResources(that, that.options.publicPath || compilation.options.output.publicPath, () => { - if (that.options.inject) { + const isInjectionAllowed = + typeof that.options.inject === 'function' + ? that.options.inject(htmlPluginData.plugin) + : that.options.inject + + if (isInjectionAllowed) { let tags = generateAppleTags(that.options, that.assets) const themeColorTag = { name: 'theme-color', From f2a6d2f5ba5b676b094fbe49edaba66a32f88beb Mon Sep 17 00:00:00 2001 From: Steel Fu Date: Wed, 30 Sep 2020 14:36:27 -0700 Subject: [PATCH 2/2] Write manifest.json to publicPath if provided --- src/injector/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/injector/index.js b/src/injector/index.js index ebfc554..a027cad 100644 --- a/src/injector/index.js +++ b/src/injector/index.js @@ -58,7 +58,7 @@ function manifest (options, publicPath, icons, callback) { const json = JSON.stringify(content, null, 2) const file = path.parse(options.filename) const filename = createFilename(file.base, json, options.fingerprints) - const output = options.includeDirectory ? path.join(file.dir, filename) : filename + const output = options.includeDirectory ? path.join(publicPath || file.dir, filename) : filename callback(null, { output, url: joinURI(publicPath, output),