swaptags

Util for swapping one set of script <tags> out for another.

npm install swaptags
4 downloads in the last week
8 downloads in the last month

swaptags

A small script for swapping <script> tags out of an html file and replacing them with the production versions.

To use:

  1. Set up a json file that contains the tags that it should replace as the keys and the values it should replace them with. For example:

    {
       "<!-- tagsfordev -->":  
         "
           <script src=\"underscore-min.js\"></script>
           <script src=\"d3.v3.min.js\"></script>
           <script src=\"sprigotclient.js\"></script>
         "
     }
    

    It's OK to have line breaks in the JSON values for now, as it will clean them out before parsing. (In the future, swaptags might use a format that's friendlier to line breaks.) The tag can be any string, but html comments work well in html files.

  2. Use those tags in the source html file to mark off what you want replace. Example:

    <!DOCTYPE html>

  3. Run the script like so:

    node swaptags.js index.html prodreplacements.json dist/index.html
    

    You will end up with an html file that looks like so:

     <script src="underscore-min.js"></script>      <script src="d3.v3.min.js"></script>      <script src="sprigotclient.js"></script>
    
    </body>
    </html>

Which, yeah, could look better.

It doesn't handle:

  • Opening and closing tags on the same line.
  • Tags broken across multiple lines.
  • Probably all sorts of other stuff.
npm loves you