node-useref is a utility package designed to parse HTML files for special 'build blocks' defined by HTML comments (e.g., `<!-- build:js ... -->`). Its primary function is to replace multiple script or link tags within these blocks with a single consolidated tag, or to remove the block entirely based on the specified type (`js`, `css`, `remove`). It outputs the modified HTML string along with a comprehensive map detailing the original assets that were part of each consolidated block, enabling subsequent build tools (like concatenators or minifiers) to process the actual files. The current stable version is 0.3.15, released in 2016. The package is effectively abandoned, with no active development or maintenance. Its key differentiator is its focused role as a HTML parser and rewritter for asset references, leaving the actual file manipulation to external tools, and its support for IE conditional comments and custom block types.
npm install node-userefVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to parse an HTML string with build blocks, transforming asset references and capturing the map of original assets for further build processing.
Consider migrating to a more actively maintained build tool or a modern module bundler (e.g., Webpack, Rollup, Vite) that offers similar asset optimization features natively.
Ensure your project uses CommonJS (`const useref = require('node-useref');`) or configure your bundler (e.g., Webpack) to correctly handle CJS modules in an ESM context.Use array destructuring for clarity: `const [html, assets] = useref(inputHtml);`
Test thoroughly with your specific Node.js version. If issues arise, consider containerizing your build environment with an older Node.js version or migrating to a modern alternative.
Use the CommonJS `require` syntax: `const useref = require('node-useref');`Add `const useref = require('node-useref');` at the top of your file before using the function.Carefully review the 'alternate search path' option in your HTML build blocks and ensure that the root path provided to your subsequent asset processing tools (e.g., for minification, concatenation) correctly aligns with the paths generated in the `assetMap`.
No dependency data recorded yet.