Skip to content

Commit

Permalink
In examples, add "svelte" to conditions in esbuild build options
Browse files Browse the repository at this point in the history
This is needed to import svelte component libraries
  • Loading branch information
BlueGreenMagick committed Jun 24, 2023
1 parent a6699eb commit ef4cdc7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ esbuild
.build({
entryPoints: ["app.js"],
mainFields: ["svelte", "browser", "module", "main"],
conditions: ["svelte"],
bundle: true,
outfile: "out.js",
plugins: [sveltePlugin()],
Expand Down Expand Up @@ -53,6 +54,7 @@ esbuild
.build({
entryPoints: ["index.js"],
mainFields: ["svelte", "browser", "module", "main"],
conditions: ["svelte"],
bundle: true,
outdir: "./dist",
plugins: [
Expand All @@ -64,6 +66,10 @@ esbuild
.catch(() => process.exit(1));
```

### `svelte` exports condition

If you are importing a svelte component library, you need to add `"svelte"` to `conditions` in esbuild build options. This lets esbuild use the `svelte` property in svelte component's `exports` conditions in `package.json` .

## Advanced

For incremental or watch build modes, esbuild-svelte will automatically cache files if they haven't changed. This allows esbuild to skip the Svelte compiler for those files altogether, saving time. Setting `cache: false` will disable this file level cache if an issue arises (please report).
Expand Down
1 change: 1 addition & 0 deletions example-js/buildscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ esbuild
.build({
entryPoints: ["./entry.js"],
mainFields: ["svelte", "browser", "module", "main"],
conditions: ["svelte"],
outdir: "./dist",
format: "esm",
logLevel: "info",
Expand Down
1 change: 1 addition & 0 deletions example-ts/buildscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ esbuild
bundle: true,
outdir: `./dist`,
mainFields: ["svelte", "browser", "module", "main"],
conditions: ["svelte"],
// logLevel: `info`,
minify: false, //so the resulting code is easier to understand
sourcemap: "inline",
Expand Down

0 comments on commit ef4cdc7

Please sign in to comment.