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

Add importmap option to Bun.build() #4458

Open
georgpukk opened this issue Sep 2, 2023 · 0 comments
Open

Add importmap option to Bun.build() #4458

georgpukk opened this issue Sep 2, 2023 · 0 comments
Labels
bundler Something to do with the bundler enhancement New feature or request

Comments

@georgpukk
Copy link

What is the problem this feature would solve?

Let's say you're developing a browser app. It has two entry points - index.js and worker.js - both of which import many modules so you use Bun.build to bundle them.

But then there are some modules that you don't want to bundle - you want them to remain external - so you add them to the external array.

And then in production you use an import map to resolve these external modules.

But because your browser app has a (module) worker, there's an issue - import maps are not available in workers.

So this is where this proposal comes in.

What is the feature you are proposing to solve the problem?

An importmap option that accepts import map object through which the bundler would map and rewrite module specifiers.

It would act like the currently existing external option but with the added capability to rewrite module specifiers.

If the same module specifier is provided both in external and importmap then the latter takes precedence.

Example usage:

await Bun.build({
	entrypoints: ['./index.js', './worker.js'],
	importmap: {
		imports: {
			three: 'https://cdn.jsdelivr.net/npm/[email protected]/+esm',
			uhtml: 'https://cdn.jsdelivr.net/npm/[email protected]/+esm'
		}
	},
	outdir: './build'
})

What alternatives have you considered?

Use Rollup with rollup-plugin-import-map.

@georgpukk georgpukk added the enhancement New feature or request label Sep 2, 2023
@Electroid Electroid added the bundler Something to do with the bundler label Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bundler Something to do with the bundler enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants