BjornTheProgrammer / bun-plugin-html

A plugin for bun build which allows html entrypoints
MIT License
34 stars 2 forks source link

Importing from modules #12

Closed kalocide closed 7 months ago

kalocide commented 7 months ago

Importing a module from NPM, throws an error. Minimum reproducible example:

<!doctype html>
<html>
    <head>
        <link rel="stylesheet" href="@radix-ui/themes/style.css">
        <script src="index.tsx" defer></script>
    </head>
    <body></body>
</html>
import html from 'bun-plugin-html'

await Bun.build({
    entrypoints: ['./src/index.html'],
    outdir: './dist',
    minify: true,
    plugins: [
        html()
    ]
});

which throws:

HTMLParseError: Specified <LINK> href '@radix-ui/themes/style.css' does not exist!

I would expect this to work, but it seems that it doesn't.

BjornTheProgrammer commented 7 months ago

Thank you for this report!

You should be able to import from node_modules like this...

<!doctype html>
<html>
    <head>
        <link rel="stylesheet" href="../node_modules/@radix-ui/themes/styles.css">
        <script src="index.tsx" defer></script>
    </head>
    <body></body>
</html>

Would you like it if it parsed a node module uniquely so that you did not have to include the ../node_modules part? If so, where would you like the file to be placed within the build dir?

kalocide commented 7 months ago

Doing this works, however it places the outputs into two directories src and node_modules within the build outputs. That may be acceptable but not for all use cases. I think ideally it would be configurable, and maybe hash asset naming could solve the issue of where to place outputs. But either way, I'm closing this as I ended up using esbuild, and I don't believe it's a killer issue.