Chore: Add Namespace builtins Vite Plugin by Natemoo-re
Closed this issue · 1 comments
Adammatthiesen commented
In order to ensure that all node builtin packages are properly prefixed with the node:
prefix a good solution is using the Namespace Builtins Vite plugin from Natemoo-re on github
The best part you ask? well The best part is this is a super simple thing to setup, and should not be hard at all to include within the core integration as a Vite plugin! see the code example below!
import { defineConfig } from 'astro/config';
import { builtinModules as builtins } from 'node:module';
function namespaceBuiltins() {
return {
name: 'namespace-builtins',
enforce: 'pre',
resolveId(id) {
if (id[0] === '.' || id[0] === '/') return;
if (builtins.includes(id)) {
return { id: `node:${id}`, external: true };
}
},
};
}
// https://astro.build/config
export default defineConfig({
vite: {
plugins: [namespaceBuiltins()],
},
});
create-issue-branch commented
Branch issue-0130 created for issue: Chore: Add Namespace builtins Vite Plugin by Natemoo-re