A metalsmith plugin to minify HTML,CSS,JSON, and SVG using html-minifier-next, lightningcss and svgo
NPM:
npm install @metalsmith/minify
Yarn:
yarn add @metalsmith/minify
Pass @metalsmith/minify to metalsmith.use :
import minify from '@metalsmith/minify'
const isDev = process.env.NODE_ENV === 'development'
metalsmith.use(minify()) // defaults
metalsmith.use(
minify({
// explicit defaults
html: {
...minify.htmlPresets.comprehensive,
pattern: '**/*.html',
conservativeCollapse: false,
minifyJS: false,
continueOnMinifyError: false,
continueOnParseError: false
// log is set to @metalsmith/minify:info by default
},
css: {
pattern: '**/*.css',
minify: !isDev,
sourceMap: isDev
},
json: false,
svg: {
pattern: '**/*.svg'
}
})
)@metalsmith/minify minifies HTML only by ef
Optional section with list or table of options, if the plugin has a lot of options
Document a first specific usage example, the title can be "Achieve x by doing y"
Document a second specific usage example, the title can be "Achieve x by doing y"
To enable debug logs, set the DEBUG environment variable to @metalsmith/minify*:
metalsmith.env('DEBUG', '@metalsmith/minify*')Alternatively you can set DEBUG to @metalsmith/* to debug all Metalsmith core plugins.
To use this plugin with the Metalsmith CLI, add @metalsmith/minify to the plugins key in your metalsmith.json file:
{
"plugins": [
{
"@metalsmith/minify": {}
}
]
}