{"library":"node-useref","title":"HTML Build Block Reference Replacement","description":"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.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install node-useref"],"cli":null},"imports":["const useref = require('node-useref');","const [transformedHtml, assetMap] = useref(inputHtml);","useref(inputHtml, { customBlockType: (content, target, options, alternateSearchPath) => { /*...*/ } });"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const useref = require('node-useref');\n\nconst sampleHtml = `\n<html>\n<head>\n  <!-- build:css css/combined.css -->\n  <link href=\"css/one.css\" rel=\"stylesheet\">\n  <link href=\"css/two.css\" rel=\"stylesheet\">\n  <!-- endbuild -->\n</head>\n<body>\n  <!-- build:js scripts/combined.js -->\n  <script type=\"text/javascript\" src=\"scripts/one.js\"></script>\n  <script type=\"text/javascript\" src=\"scripts/two.js\"></script>\n  <!-- endbuild -->\n\n  <!-- build:js scripts/async.js async data-foo=\"bar\" -->\n  <script type=\"text/javascript\" src=\"scripts/three.js\"></script>\n  <script type=\"text/javascript\" src=\"scripts/four.js\"></script>\n  <!-- endbuild -->\n\n  <!-- build:remove -->\n  <p>This content will be removed.</p>\n  <!-- endbuild -->\n</body>\n</html>`;\n\nconst [transformedHtml, assetMap] = useref(sampleHtml);\n\nconsole.log('--- Transformed HTML ---');\nconsole.log(transformedHtml);\nconsole.log('\\n--- Asset Map ---');\nconsole.log(JSON.stringify(assetMap, null, 2));\n\n/*\nExample Expected Output for transformedHtml:\n<html>\n<head>\n  <link rel=\"stylesheet\" href=\"css/combined.css\"/>\n</head>\n<body>\n  <script src=\"scripts/combined.js\"></script>\n  <script src=\"scripts/async.js\" async data-foo=\"bar\" ></script>\n\n\n</body>\n</html>\n*/","lang":"javascript","description":"Demonstrates how to parse an HTML string with build blocks, transforming asset references and capturing the map of original assets for further build processing.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}