Expose partytown config options from astro plugin (#6667)

This commit is contained in:
Smit Patel 2023-03-28 14:14:54 +05:30 committed by GitHub
parent 9352e0056c
commit aff53c109c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 8 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/partytown': minor
---
Expose more partytown config properties

View file

@ -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

View file

@ -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';
@ -10,10 +11,7 @@ const resolve = createRequire(import.meta.url).resolve;
type PartytownOptions =
| {
config?: {
forward?: string[];
debug?: boolean;
};
config?: PartytownConfig;
}
| undefined;
@ -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 }) => {