# html-webpack-skip-assets-plugin

> a plugin for html-webpack-plugin to skip adding certain output files to the html

Latest version **1.0.4** (published 2024-03-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install html-webpack-skip-assets-plugin
pnpm add html-webpack-skip-assets-plugin
yarn add html-webpack-skip-assets-plugin
bun add html-webpack-skip-assets-plugin
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2024-03-29 |
| First published | 2020-05-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.5 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 19 |
| Author | swimmadude66 |
| Maintainers | swimmadude66 |
| Keywords | html-webpack-plugin, exclude-assets, assets, polyfills, webpack, plugin |

## Links

- npm: https://www.npmjs.com/package/html-webpack-skip-assets-plugin
- Repository: https://github.com/swimmadude66/html-webpack-skip-assets-plugin
- Homepage: https://github.com/swimmadude66/html-webpack-skip-assets-plugin#readme
- Issues: https://github.com/swimmadude66/html-webpack-skip-assets-plugin/issues
- npm.io page: https://npm.io/package/html-webpack-skip-assets-plugin

## Dependencies (1)

- [minimatch](https://npm.io/package/minimatch.md) 3.0.5

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2024-03-29
- 1.0.3 — 2021-10-18
- 1.0.2 — 2021-06-24
- 1.0.1 — 2021-02-12
- 1.0.0 — 2021-02-04
- 0.0.2 — 2020-05-01
- 0.0.1 — 2020-05-01

## README

# Html Webpack Skip Assets Plugin
_Skip adding certain output files to the html file. Built as a drop-in replacement for [html-webpack-exclude-assets-plugin](https://www.npmjs.com/package/html-webpack-exclude-assets-plugin) and works with newer [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin) versions_

![build-plugin](https://github.com/swimmadude66/html-webpack-skip-assets-plugin/workflows/build-plugin/badge.svg?branch=master)

[![NPM](https://nodei.co/npm/html-webpack-skip-assets-plugin.png?compact=true)](https://npmjs.org/package/html-webpack-skip-assets-plugin)


## Configuration

1. Install via `npm i -D html-webpack-skip-assets-plugin`
1. Add to your webpack config AFTER HtmlWebpackPlugin
```javascript
    var HtmlWebpackSkipAssetsPlugin = require('html-webpack-skip-assets-plugin').HtmlWebpackSkipAssetsPlugin;
    // OR for import style
    import {HtmlWebpackSkipAssetsPlugin} from 'html-webpack-skip-assets-plugin'
    ...
    plugins: [
        new HtmlWebpackPlugin({
            filename: join(OUTPUT_DIR, './dist/index.html'),
            // Skip Assets options can be added here
            excludeAssets: ['polyfill.**.js', /styles\..*js$/i, (asset) => (asset.attributes && asset.attributes['x-skip'])]
            // OR
            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, (asset) => (asset.attributes && asset.attributes['x-skip'])]
            // OR
            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)), 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

This exclusion will also work for `inject: false`:

```js
new HtmlWebpackPlugin({
  inject: false,
  excludeAssets: ['polyfill.**.js', /styles\..*js$/i, (asset) => (asset.attributes && asset.attributes['x-skip'])]
  templateContent: ({htmlWebpackPlugin}) => `
    <html>
      <head>
        ${htmlWebpackPlugin.tags.headTags}
      </head>
      <body>
        ${htmlWebpackPlugin.tags.bodyTags}
      </body>
    </html>
  `
})
```

## Testing
Testing is done via ts-node and mocha. Test files can be found in `/spec`, and will be auto-discovered as long as the file ends in `.spec.ts`. Just run `npm test` after installing to see the tests run.

---
_Source: https://npm.io/package/html-webpack-skip-assets-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
