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

Expose partytown config options from astro plugin #6667

Merged
merged 1 commit into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chilly-dingos-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/partytown': minor
---

Expose more partytown config properties
2 changes: 1 addition & 1 deletion packages/integrations/partytown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default defineConfig({
});
```

This mirrors the [Partytown config object](https://partytown.builder.io/configuration), but only `debug` and `forward` are exposed by this integration.
This mirrors the [Partytown config object](https://partytown.builder.io/configuration).

### config.debug

Expand Down
15 changes: 8 additions & 7 deletions packages/integrations/partytown/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { partytownSnippet } from '@builder.io/partytown/integration';
import type { PartytownConfig } from '@builder.io/partytown/integration';
import { copyLibFiles, libDirPath } from '@builder.io/partytown/utils';
import type { AstroConfig, AstroIntegration } from 'astro';
import * as fs from 'fs';
Expand All @@ -10,10 +11,7 @@ const resolve = createRequire(import.meta.url).resolve;

type PartytownOptions =
| {
config?: {
forward?: string[];
debug?: boolean;
};
config?: PartytownConfig;
}
| undefined;

Expand All @@ -31,9 +29,12 @@ export default function createPlugin(options: PartytownOptions): AstroIntegratio
hooks: {
'astro:config:setup': ({ config: _config, command, injectScript }) => {
const lib = `${appendForwardSlash(_config.base)}~partytown/`;
const forward = options?.config?.forward || [];
const debug = options?.config?.debug || command === 'dev';
partytownSnippetHtml = partytownSnippet({ lib, debug, forward });
const partytownConfig = {
...options?.config,
lib,
debug: options?.config?.debug ?? command === 'dev',
};
partytownSnippetHtml = partytownSnippet(partytownConfig);
injectScript('head-inline', partytownSnippetHtml);
},
'astro:config:done': ({ config: _config }) => {
Expand Down