Skip to content

Commit

Permalink
add support for callback function, fix regex bug
Browse files Browse the repository at this point in the history
  • Loading branch information
swimmadude66 committed Feb 12, 2021
1 parent 369b549 commit 29e45d1
Show file tree
Hide file tree
Showing 5 changed files with 384 additions and 361 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# 1.0.1 - Improved matching logic
- Fixed an issue with global regexes not matching multiple files (closes #5)
- Added support for a callback function to test an asset for skipping (closes #6)

To use the new function matcher, add a function to either array in the options which takes an `HtmlTagObject` from html-webpack-plugin as an argument, and returns `true` to skip the file, or `false` to include it.

New mocha tests have also been added to test for both of the above fixes. The mocha test file has also been refactored to reduce duplicate testing effort and easily expand coverage.

# 1.0.0 - Webpack 5 support
- verify support for webpack5 and html-webpack-plugin 5


# 0.0.2
## Build tool and readme changes
No functional difference, just pinning dependencies and updating readme
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ _Skip adding certain output files to the html file. Built as a drop-in replaceme
new HtmlWebpackPlugin({
filename: join(OUTPUT_DIR, './dist/index.html'),
// Skip Assets options can be added here
excludeAssets: ['polyfill.**.js', /styles\..*js$/i]
excludeAssets: ['polyfill.**.js', /styles\..*js$/i, (asset) => (asset.attributes && asset.attributes['x-skip'])]
// OR
skipAssets: ['polyfill.**.js', /styles\..*js$/i]
skipAssets: ['polyfill.**.js', /styles\..*js$/i, (asset) => (asset.attributes && asset.attributes['x-skip'])]
}),
new HtmlWebpackSkipAssetsPlugin({
// or they can be passed in on the plugin. These 4 lists are combined before running
excludeAssets: ['polyfill.**.js', /styles\..*js$/i]
excludeAssets: ['polyfill.**.js', /styles\..*js$/i, (asset) => (asset.attributes && asset.attributes['x-skip'])]
// OR
skipAssets: ['polyfill.**.js', /styles\..*js$/i]
skipAssets: ['polyfill.**.js', /styles\..*js$/i, (asset) => (asset.attributes && asset.attributes['x-skip'])]
})
]
```

The plugin takes a configuration argument with a key called `skipAssets`. This is an array of file globs (provided via [minimatch](https://github.com/isaacs/minimatch)) or regex patterns representing which output files to skip adding to the output html. In order to ease migration from [html-webpack-exclude-assets-plugin](https://www.npmjs.com/package/html-webpack-exclude-assets-plugin), the plugin also supports passing `excludeAssets` as the option key, as well as the ability to add either key to the HtmlWebpackPlugin options. All provided lists will be concatenated and used to filter the assets.
The plugin takes a configuration argument with a key called `skipAssets`. This is an array of file globs (provided via [minimatch](https://github.com/isaacs/minimatch)), regex patterns, or functions which accept the asset and return a boolean representing wheter or not to skip adding to the output html. In order to ease migration from [html-webpack-exclude-assets-plugin](https://www.npmjs.com/package/html-webpack-exclude-assets-plugin), the plugin also supports passing `excludeAssets` as the option key, as well as the ability to add either key to the HtmlWebpackPlugin options. All provided lists will be concatenated and used to filter the assets.

## Custom insertion

Expand All @@ -41,7 +41,7 @@ This exclusion will also work for `inject: false`:
```js
new HtmlWebpackPlugin({
inject: false,
excludeAssets: ['polyfill.**.js', /styles\..*js$/i]
excludeAssets: ['polyfill.**.js', /styles\..*js$/i, (asset) => (asset.attributes && asset.attributes['x-skip'])]
templateContent: ({htmlWebpackPlugin}) => `
<html>
<head>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "html-webpack-skip-assets-plugin",
"version": "1.0.0",
"version": "1.0.1",
"description": "a plugin for html-webpack-plugin to skip adding certain output files to the html",
"main": "dist/plugin.js",
"scripts": {
Expand Down
Loading

0 comments on commit 29e45d1

Please sign in to comment.