remy / inliner

Node utility to inline images, CSS and JavaScript for a web page - useful for mobile sites
MIT License
1.1k stars 165 forks source link

Request further syntax assistance using inliner in a script to parse folders #234

Open SugarRayLua opened 6 months ago

SugarRayLua commented 6 months ago

Hi and thanks for making the very useful inliner package!

I a mobile programmer and javascript novice and recently began using node.js ported to iOS (iPad): https://apps.apple.com/us/app/node-js-lab/id1550710789

Unfortunately, it doesn't yet have CLI support. Thus, I need to install npm packages like inliner and run them via javascript in the app. I modified the example on inliner's github and the script below worked somewhat (some of my .js and images were inclined) but not all of them:

var Inliner = require('inliner');
const fs = require('fs');

new Inliner('./rpssl/index.html', function (error, html) {
  fs.writeFile("./testIndex.html", html, function(err) {
      if(err) {
          return console.log(err);
      } else {
          console.log("The file was saved!");
      }
  });
});

The directory I set up for inliner to parse looks like this:

/ (root)
test.js (containing the script above)
rpssl (dir)
     index.html 
     (multiple).js files
     manifest.json
     icon.png
     sprites (dir-- containing multiple .png sprites)
     fonts (dir -- containing multiple .ttf fonts)

It looks like most who have written in issues have been using the command line so would appreciate any assistance you could provide in terms of how I would set up inliner in the .js script I wrote to be able to parse the different directories to inline their contents into the single file "testIndex.html"

Thanks :-)