metalsmith-minify-tags v1.0.0
metalsmith-minify-tags
A metalsmith plugin for minifying generic HTML tags in HTML files.
This plugin minifies HTML tags in all HTML files that have no sematic meaning. By running this plugin, all of the <div>
and <span>
tags will be minified to <d>
and <n>
tags respectively, and updates all of the style sheets to use these new minified tags. Under the hood, metalsmith-minify-tags
uses the jsdom
library to manipulate the HTML files and css-tree
to manipulate the CSS source code.
Installation
npm install metalsmith-minify-tags
Usage
To use this plugin, simply add it to the existing plugins in your Metalsmith source file or include it in the Metalsmith JSON file:
JavaScript
const Metalsmith = require('metalsmith');
const minifyTags = require('metalsmith-minify-tags');
Metalsmith(__dirname)
.use(minifyTags())
.build((err, files) => {
if (err) { throw err; }
});
JSON
{
"plugins": {
"metalsmith-minify-tags": {}
}
}
Options
You can pass options to metalsmith-minify-tags
with the Javascript API or CLI. The options are:
- htmlPattern: optional. Only HTML files that match this pattern will be processed. Accepts a string or an array of strings. The default is
**/*.html
. - cssPattern: optional. Only CSS source files that match this pattern will be processed. Accepts a string or an array of strings. The default is
**/*.css
.
htmlPattern
Only HTML files that match this pattern will be processed for tag minification. So this Metalsmith JavaScript configuration or metalsmith.json
:
JavaScript
const Metalsmith = require('metalsmith');
const minifyTags = require('metalsmith-minify-tags');
Metalsmith(__dirname)
.use(minifyTags({
htmlPattern: 'blog/**/*.html',
}))
.build((err, files) => {
if (err) { throw err; }
});
JSON
{
"source": "src",
"destination": "build",
"plugins": {
"metalsmith-minify-tags": {
"tagsPattern": "blog/**/*.html"
}
}
}
Would only process HTML files within the ./src/blog
folder, because the pattern
is relative to your source folder. See multimatch
for further details.
cssPattern
Only CSS files that match this pattern will be processed for tag minification. So this Metalsmith JavaScript configuration or metalsmith.json
:
JavaScript
const Metalsmith = require('metalsmith');
const minifyTags = require('metalsmith-minify-tags');
Metalsmith(__dirname)
.use(minifyTags({
cssPattern: 'blog/**/*.css',
}))
.build((err, files) => {
if (err) { throw err; }
});
JSON
{
"source": "src",
"destination": "build",
"plugins": {
"metalsmith-minify-tags": {
"cssPattern": "blog/**/*.js"
}
}
}
Would only process CSS files within the ./src/blog
folder, because the pattern
is relative to your source folder. See multimatch
for further details.
License
3 years ago