script-ext-html-webpack-plugin
Advanced tools
Comparing version 2.0.3 to 2.1.0
@@ -8,6 +8,24 @@ 'use strict'; | ||
const hasScriptName = tag => tag.attributes && tag.attributes.src; | ||
const isResourceLink = (tag) => tag.tagName === 'link' && tag.attributes && tag.attributes.as === 'script'; | ||
const getRawScriptName = tag => (tag.attributes && tag.attributes.src) || ''; | ||
const hasScriptName = tag => { | ||
if (isScript(tag)) { | ||
return tag.attributes && tag.attributes.src; | ||
} else if (isResourceLink(tag)) { | ||
return tag.attributes && tag.attributes.href; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
const getRawScriptName = tag => { | ||
if (isScript(tag)) { | ||
return (tag.attributes && tag.attributes.src) || ''; | ||
} else if (isResourceLink(tag)) { | ||
return (tag.attributes && tag.attributes.href) || ''; | ||
} else { | ||
return ''; | ||
} | ||
}; | ||
const getPublicPath = options => { | ||
@@ -51,4 +69,5 @@ const output = options.compilationOptions.output; | ||
hasScriptName, | ||
isResourceLink, | ||
isScript, | ||
matches | ||
}; |
@@ -8,2 +8,3 @@ 'use strict'; | ||
const getScriptName = common.getScriptName; | ||
const isResourceLink = common.isResourceLink; | ||
const isScript = common.isScript; | ||
@@ -22,3 +23,3 @@ const matches = common.matches; | ||
const updateElement = (options, tag) => { | ||
return (isScript(tag)) | ||
return (isScript(tag) || isResourceLink(tag)) | ||
? updateScriptElement(options, tag) | ||
@@ -25,0 +26,0 @@ : tag; |
@@ -9,2 +9,3 @@ 'use strict'; | ||
const debug = common.debug; | ||
const isScript = common.isScript; | ||
const matches = common.matches; | ||
@@ -35,4 +36,2 @@ const getScriptName = common.getScriptName; | ||
const isScript = (tag) => tag.tagName === 'script'; | ||
const updateScriptElement = (assets, options, tag) => { | ||
@@ -39,0 +38,0 @@ debug(`${CONSTANTS.EVENT}: processing <script> element: ${JSON.stringify(tag)}`); |
{ | ||
"name": "script-ext-html-webpack-plugin", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"description": "Enhances html-webpack-plugin functionality with async and defer attributes for script elements", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -178,2 +178,19 @@ Script Extension for HTML Webpack Plugin | ||
All scripts are preloaded with a ```crossorigin``` attribute set to enable CDN's: | ||
```javascript | ||
plugins: [ | ||
new HtmlWebpackPlugin(), | ||
new ScriptExtHtmlWebpackPlugin({ | ||
custom { | ||
test: /\.js$/, | ||
attribute: 'crossorigin' | ||
value: 'anonymous' | ||
} | ||
preload: { | ||
test: /\.js$/ | ||
} | ||
}) | ||
] | ||
``` | ||
All asynchronous scripts are added as `preload` resource hints. All other scripts are `async`: | ||
@@ -289,2 +306,3 @@ ```javascript | ||
Notes: | ||
- custom attributes will be added to resource hints with the same *script matching pattern*. This is useful for adding such attributes as ```crossorigin="anonymous"``` - see the Configuration Examples above; | ||
- for more on resource hints, see the [`w3c`](https://www.w3.org/TR/resource-hints) definition; | ||
@@ -298,2 +316,5 @@ - for a more complete solution that allows the preloading\fetching of assets other than scripts, see the [resource-hints-webpack-plugin](https://github.com/jantimon/resource-hints-webpack-plugin). | ||
v2.1.x | ||
* custom attributes now added to resource hints too (see [pull request 53](https://github.com/numical/script-ext-html-webpack-plugin/pull/53) for discussion) | ||
v2.0.x | ||
@@ -300,0 +321,0 @@ * support html-webpack-plugin 4.x - huge thanks to [@snadn](https://github.com/snadn) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34222
477
370