Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

external css #107

Open
zoutigo opened this issue Nov 15, 2021 · 1 comment
Open

external css #107

zoutigo opened this issue Nov 15, 2021 · 1 comment

Comments

@zoutigo
Copy link

zoutigo commented Nov 15, 2021

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 <style>...<style> in each html template.

Thanks in advance

@mbaumgartl
Copy link

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);
})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants