1.0.7 • Published 3 years ago

html-webpack-transform-plugin v1.0.7

Weekly downloads
39
License
MIT
Repository
github
Last release
3 years ago

Assets Transform extension for the HTML Webpack Plugin

License npm Build Status FOSSA Status

About

This plugin will allow you to transform asset tags generated by html-webpack-plugin.

Installation

Install the plugin with npm:

npm i --save-dev html-webpack-transform-plugin

Install the plugin with yarn:

yarn add --dev html-webpack-transform-plugin

Basic Usage

In the plugins section of your webpack config file, include the following:

plugins: [
  new HtmlWebpackPlugin(),
  new HtmlWebpackTransformPlugin()
]

Options

NameTypeDefaultDescription
attributes{Object}{}Map of attributes to add
pathPrefix{String}''Path prefix to use with each asset url
transform{Function}tag => tagA callback function that is execute on each tag to allow any transformation of tags. Function must return modified tag object
replacePublicPath{Boolean}falseUsed with pathPrefix option. If true - publicPath from webpack options will be replaced with pathPrefix

Examples

Add crossorigin attribue for each script tag:

new HtmlWebpackTransformPlugin({
  attributes: {script: {crossorigin: 'anonymous'}},
}),

Replace public path with ejs template variable for dynamic paths with expresjs:

new HtmlWebpackTransformPlugin({
  pathPrefix: '<%= assetsPath %>/',
  replacePublicPath: true,
}),

Do anything else with the tags using transform callback:

new HtmlWebpackTransformPlugin({
  transform: tag => {
    // add additional properties
    // add path prefix or remove public path
    // or anything else
    return tag;
  },
}),

License

FOSSA Status

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago