inline-css icon indicating copy to clipboard operation
inline-css copied to clipboard

external css

Open zoutigo opened this issue 3 years ago • 1 comments

Hello.

May be i misunderstood something, but, is there any solution to make it work with external css , i mean <link rel="stylesheet" href="./style.css" />

Because if i have many templates , i don't want to copy/paste

Thanks in advance

zoutigo avatar Nov 15 '21 13:11 zoutigo

You have to use the url config property.

// import or require fs/promises + other modules
const baseUrl = url.pathToFileURL(__dirname + path.sep).toString();
(async () => {
    const htmlFile = path.join(__dirname, 'index.html');
    const html = await fs.readFile(htmlFile, { encoding: 'utf-8' });
    const body = await inlineCss(
        `<link href="./style.css" type="text/css" rel="stylesheet">${html}`,
        { url: baseUrl },
    );

    console.log(body);
})();

mbaumgartl avatar Jan 21 '22 17:01 mbaumgartl