Add base config option to partytown snippet generation (#3437)

* fix: add base config option to partytown snippet generation

* add changeset

* fix: handle config.base for partytown

Co-authored-by: Nate Moore <nate@skypack.dev>
This commit is contained in:
Caio Ferrarezi 2022-05-24 17:44:40 -03:00 committed by GitHub
parent 03b2ef4b67
commit 78e962f744
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/partytown': patch
---
Fix partytown script generation to get astro base config option

View file

@ -25,18 +25,20 @@ export default function createPlugin(options: PartytownOptions): AstroIntegratio
name: '@astrojs/partytown',
hooks: {
'astro:config:setup': ({ config: _config, command, injectScript }) => {
const lib = `${_config.base}~partytown/`;
const forward = options?.config?.forward || [];
const debug = options?.config?.debug || command === 'dev';
partytownSnippetHtml = partytownSnippet({ debug, forward });
partytownSnippetHtml = partytownSnippet({ lib, debug, forward });
injectScript('head-inline', partytownSnippetHtml);
},
'astro:config:done': ({ config: _config }) => {
config = _config;
},
'astro:server:setup': ({ server }) => {
const lib = `${config.base}~partytown/`;
server.middlewares.use(
sirv(partytownLibDirectory, {
mount: '/~partytown',
mount: lib,
dev: true,
etag: true,
extensions: [],