hwp-attributes-plugin
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published

hwp-attributes-plugin

CI

Plugin to add various attributes to script tags injected by html-webpack-plugin

Installation

npm i -D hwp-attributes-plugin

Usage

import { HwpAttributesPlugin } from 'hwp-attributes-plugin';

// Webpack configuration object
export default {

    plugins: [
        new HtmlWebpackPlugin({ /* ... */ }),
        new HwpAttributesPlugin({
            module: ['**.mjs'],
            nomodule: ['polyfills.js'],
            async: ['some-async-script.js', 'another-async-script.js'],
            defer: ['script-to-defer.*.js'],
        }),
    ],
};

To configure the plugin, pass an object with the following keys to its constructor (all keys are optional):

  • module: patterns of scripts that should have the module attribute added;
  • nomodule: patterns of scripts that should have the nomodule attribute added;
  • async: patterns of scripts that should have the async attribute added;
  • defer: patterns of scripts that should have the defer attribute added.

The plugin performs pattern matching with the help of minimatch.

The module and nomodule attributes are mutually exclusive, module takes precedence. If the same file matches both module and nomodule patterns, it will have the module attribute.

Dependents (0)

Package Sidebar

Install

npm i hwp-attributes-plugin

Weekly Downloads

41

Version

2.1.1

License

MIT

Unpacked Size

9.01 kB

Total Files

6

Last publish

Collaborators

  • wwa