Skip to content

Repository files navigation

htmlclean-loader

npmGitHub issuesDavidlicense

htmlclean loader module for webpack.

If you want to just clean files, Command Line Tool is easy way.

Simple and safety HTML/SVG cleaner to minify without changing its structure.
See htmlclean for options and more information about htmlclean.

Installation

npm install --save-dev htmlclean-loader htmlclean

Usage

Documentation:

For example:

// app.jsvarheaderHtml=require('./header.html');document.getElementById('header').innerHTML=headerHtml;
// webpack.config.jsmodule.exports={entry: './app.js',output: {filename: 'bundle.js'},module: {rules: [{test: /\.html$/,loader: 'htmlclean-loader'}]}};

Options

You can specify options via query parameters or an options (or htmlcleanLoader for webpack v1) object in webpack configuration.

For example:

// webpack.config.jsmodule.exports={// ...module: {rules: [{test: /\.html$/,loader: 'htmlclean-loader',options: {protect: /<\!--%fooTemplate\b.*?%-->/g,edit: function(html){returnhtml.replace(/foo/g,'bar');}}}]}};

See htmlclean for the options.
Also, the following additional option is available.

raw

Type: boolean
Default: Automatic

This loader outputs a JavaScript code when it is specified as a final loader, otherwise it outputs a raw HTML code for next loader that expects it to be given, automatically.
That is, when it is specified as a final loader, it works like that a raw-loader is chained to the list of loaders.
For example, the following two codes work same:

// webpack.config.jsmodule.exports={// ...module: {// Actually, `raw-loader` is unnecessary.rules: [{test: /\.html$/,use: ['raw-loader','htmlclean-loader']}]// htmlclean-loader passes a raw HTML code to raw-loader,// and raw-loader changes it to a JavaScript code and outputs it.}};
// webpack.config.jsmodule.exports={// ...module: {rules: [{test: /\.html$/,loader: 'htmlclean-loader'}]// htmlclean-loader outputs a JavaScript code.}};

By default, it chooses the JavaScript code or the raw HTML code automatically.
If true is specified for raw option, it chooses a raw HTML code always. If false is specified for raw option, it chooses a JavaScript code always.

About

htmlclean loader module for webpack - Simple and safety HTML/SVG cleaner to minify without changing its structure.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages