1.0.12 • Published 6 years ago

htmlclean-loader v1.0.12

Weekly downloads
90
License
MIT
Repository
github
Last release
6 years ago

htmlclean-loader

npm GitHub issues David license

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.js
var headerHtml = require('./header.html');
document.getElementById('header').innerHTML = headerHtml;
// webpack.config.js
module.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.js
module.exports = {
  // ...
  module: {
    rules: [{
      test: /\.html$/,
      loader: 'htmlclean-loader',
      options: {
        protect: /<\!--%fooTemplate\b.*?%-->/g,
        edit: function(html) {
          return html.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.js
module.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.js
module.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.

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago