Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

Allow filtering which file to inject manifest into #138

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 6 additions & 1 deletion src/generators/tapable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/injector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down