Registry /
devops / minify-template-literal-loader
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
webpack rule configuration
✓ {
test: /\.template\.js$/,
loader: 'minify-template-literal-loader',
options: { collapseWhitespace: true }
}
✗ Using loader after babel instead of before
Place loader before transpilers like babel; webpack runs loaders right-to-left, bottom-to-top.
require('html-minifier').minify
✓ const { minify } = require('html-minifier');
Internal usage; not typically imported by user.
package.json dependency
✓ "minify-template-literal-loader": "^0.0.3"
✗ Omitting html-minifier from peerDependencies
Installing without html-minifier causes runtime error.
Configures webpack to minify template literals in .template.js files before further processing.
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.template\.js$/,
use: {
loader: 'minify-template-literal-loader',
options: {
collapseWhitespace: true,
conservativeCollapse: false,
removeComments: true
}
}
},
{
test: /\.js$/,
exclude: /\.template\.js$/,
use: 'babel-loader'
}
]
}
};
Debug
Known issues
gotchaLoader must be applied before transpilers like babel due to webpack's right-to-left loader execution order.fixEnsure minify-template-literal-loader appears after babel-loader in the rules array (since webpack processes bottom-to-top).
affects: *
deprecatedhtml-minifier is unmaintained and may have security issues; consider using html-minifier-terser instead.fixReplace peer dependency html-minifier with html-minifier-terser and update options accordingly.
affects: >=0.0.3
gotchaThe loader only minifies template literals that are exported or assigned to variables; inline expressions like `${}` may not be fully optimized.fixManually review template literals with complex interpolations; consider using a babel plugin for more comprehensive minification.
affects: *
breakingNo breaking changes reported due to minimal versions and low usage.
Errors
Common errors & fixes
Module not found: Error: Can't resolve 'html-minifier'
Missing required peer dependency html-minifier.
fixnpm install html-minifier --save-dev
Error: html-minifier is not a function
Incorrect peer dependency version or html-minifier not installed.
fixEnsure html-minifier is properly installed: npm install html-minifier@3.5.7 --save-dev
Module parse failed: Unexpected token (1:0)
Loader not applied; template literals are not being processed before transpilation.
fixAdd loader rule for .template.js files and ensure it is placed before babel-loader in the config.
Audit
Dependencies
html-minifierrequiredpeer dependency for HTML minification