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

Documentation, update example? #233

Open tamusjroyce opened 1 year ago

tamusjroyce commented 1 year ago
const inliner = require('inliner');
const fs = require('fs');
const path = require('path');

const htmlFilePath = fs.existsSync(fs.existsSync('./dist/index.html')) ? './dist/index.html' : './src/renderer/dist/index.html';
const inlineFilePath = fs.existsSync(fs.existsSync('./dist/index.html')) ? './dist/inline.html' : './src/renderer/dist/inline.html';

const inlined = new inliner(htmlFilePath, undefined, (err, html) => {
    fs.writeFileSync(path.resolve(path.join(process.cwd(), inlineFilePath)), html, 'utf8');
    console.log('done');
});
inlined.promise.then((html) => {
    // Why is html undefined?
    console.log('promise completed');
});

Options seem to come before the callback Could you support inlined.promise returning html as well?

I'm not sure why. But when I run npx run inliner ./index.html >> ./inline.html I get an empty ./inline.html file. I am running in powershell (vscode on windows. meh.) and node 14.x. Not quite sure why async is returning early.

Otherwise, this works great! Thank you!

tamusjroyce commented 1 year ago

My use case: Inline Angular so it can be pre-loaded in puppeteer. When a request comes in through express endpoint, the browser will already be preloaded.

And I could do a bunch of sheet and javascript imports. But it is nicer, repeatable, and secure (I can remove --no-sandbox) if everything is just inlined.