Skip to content

Instantly share code, notes, and snippets.

@kidonng
Last active July 13, 2023 00:10
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kidonng/b8273a55854bbe8f1402f188755632e3 to your computer and use it in GitHub Desktop.
Save kidonng/b8273a55854bbe8f1402f188755632e3 to your computer and use it in GitHub Desktop.
Compile & bundle SolidJS for browsers with Deno https://github.com/solidjs/solid/discussions/873#discussioncomment-3395136
import {extname} from 'path'
import {build, stop} from 'esbuild'
import {solidPlugin} from 'esbuild-plugin-solid'
import {denoPlugin} from 'esbuild_deno_loader'
const [input] = Deno.args
const ext = extname(input)
const compileOutput = input.replace(ext, '.compiled.js')
const bundleOutput = input.replace(ext, '.bundle.js')
await build({
entryPoints: [input],
outfile: compileOutput,
// Bundle relative imports
bundle: true,
format: 'esm',
// Need to mark every bare import as external
external: ['solid-js'],
// Tree-shaking is done below
treeShaking: false,
// Compile SolidJS JSX
plugins: [solidPlugin()],
})
await build({
entryPoints: [compileOutput],
outfile: bundleOutput,
// Bundle again to deal with imports introduced in compilation
bundle: true,
minify: true,
// Resolve dependencies from import map
plugins: [
denoPlugin({
importMapURL: new URL('https://gist.github.com/kidonng/b8273a55854bbe8f1402f188755632e3/raw/import_map.json'),
})
],
})
stop()
Deno.removeSync(compileOutput)
{
"imports": {
"esbuild_deno_loader": "https://deno.land/x/esbuild_deno_loader@0.5.2/mod.ts?external=esbuild",
"esbuild-plugin-solid": "https://esm.sh/esbuild-plugin-solid@0.4.2?external=esbuild",
"path": "https://deno.land/std@0.150.0/path/mod.ts",
"esbuild": "https://deno.land/x/esbuild@v0.15.3/mod.js",
"solid-js": "https://esm.sh/solid-js@1.4.8?target=esnext",
"solid-js/web": "https://esm.sh/solid-js@1.4.8/web?target=esnext"
}
}
@kilisio
Copy link

kilisio commented Jun 19, 2023

This was a great help. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment