You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8774106
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: frontend/purestack.studio/guides/extending/plugins.mdx
+61-2Lines changed: 61 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,49 @@ A plugin is a named object that extends how PureStack builds your site. Each of
29
29
30
30
## Add your first plugin
31
31
32
+
To use an installed plugin without writing TypeScript, list its package in
33
+
`siteConfig.json`. For example, install `@purestack/ts-images`, then enable image
34
+
optimization:
35
+
36
+
```json
37
+
{
38
+
"plugins": ["@purestack/ts-images#imagesPlugin"],
39
+
"extensions": {
40
+
"images": { "widths": [480, 960, 1440] }
41
+
}
42
+
}
43
+
```
44
+
45
+
Use `package#exportName` to select a named export, for example
46
+
`"@purestack/ts-images#imagesPlugin"`. Without a suffix, PureStack selects the
47
+
default export. Each selected export must be a plugin object or a no-argument
48
+
factory. Packages can expose multiple plugins; list each export separately:
49
+
50
+
```json
51
+
{
52
+
"plugins": [
53
+
"@purestack/ts-page-scripts#consentPlugin",
54
+
"@purestack/ts-page-scripts#analyticsPlugin"
55
+
]
56
+
}
57
+
```
58
+
59
+
The suffix is the JavaScript export name, not the plugin's `name`. Package
60
+
subpaths also work: `package/subpath#exportName`. PureStack loads selections for
61
+
builds, publishing, and development, and reloads them when this JSON file changes.
62
+
Each plugin owns its settings; listing `imagesPlugin` enables
63
+
its defaults even without `extensions.images`. Set `extensions.images.enabled`
64
+
to `false` to disable optimization. An explicit plugin instance in
65
+
`purestack.config.ts` replaces a JSON-selected plugin with the same name.
66
+
67
+
Both config formats use PureStack's own copy of a package when available so
68
+
shared registries stay together; other packages resolve from the site.
69
+
Plugin declarations execute installed JavaScript with the build process's
70
+
permissions, so treat changes to `plugins` as code changes even when a CMS edits
71
+
other site settings.
72
+
73
+
For local plugins and custom callbacks, use the TypeScript setup below.
74
+
32
75
Keep plugins in a folder of their own, beside the content folder:
33
76
34
77
```text
@@ -111,7 +154,23 @@ Metadata defaults compose through `headConfig({ site, pageInfo })` in plugin ord
111
154
112
155
Auth hints, consent, and analytics are independent plugins in `ts-page-scripts`. The analytics plugin contributes automatic GA4 consent services during configuration resolution, before any factory or lifecycle hook runs. Omitting it removes automatic registration and direct tracking scripts. Explicitly configured consent services remain available. Analytics never bypasses enabled consent when the consent runtime plugin is omitted.
113
156
114
-
To choose the standard integrations yourself, disable the automatic set and list the plugins you want. The factories are exported from `purestack`, `@purestack/ts-ssg`, and their individual packages:
157
+
To choose the standard integrations yourself, disable the automatic set and list the plugins you want in `siteConfig.json`:
158
+
159
+
```json
160
+
{
161
+
"defaultPlugins": false,
162
+
"plugins": [
163
+
"@purestack/ts-theme#themePlugin",
164
+
"@purestack/ts-components#componentsPlugin"
165
+
]
166
+
}
167
+
```
168
+
169
+
Omitting `defaultPlugins` keeps the automatic set enabled. An explicit
170
+
TypeScript/programmatic `defaultPlugins` value overrides the JSON flag.
171
+
Development reloads changes to either setting.
172
+
173
+
The same selection is available in `purestack.config.ts`. The factories are exported from `purestack`, `@purestack/ts-ssg`, and their individual packages:
`resolveSiteConfig(input, { plugins, defaultPlugins })` composes the same selected plugins as a build, including the standard plugins by default. Plugin-owned sections (`style`, `docLayout`, `pageToc`, `logo`, `auth`, `consent`, `analytics`, `pagefind`, and `preview`) are optional in `SiteConfig`: an omitted plugin does not supply defaults or validate its unused input. A replacement plugin reads its settings from `input` and `file`, then contributes normalized config. Analytics also resolves explicitly configured consent when its browser runtime is omitted, so enabled consent is never bypassed. Configuration contributions are synchronous and may run whenever a project configuration is resolved; keep file writes and other side effects in lifecycle hooks.
237
+
`resolveSiteConfig(input, { plugins, defaultPlugins })` composes the supplied plugin instances with the standard plugins by default. This synchronous helper does not apply JSON plugin selection (`plugins` or `defaultPlugins`) or load `purestack.config.ts`. Plugin-owned sections (`style`, `docLayout`, `pageToc`, `logo`, `auth`, `consent`, `analytics`, `pagefind`, and `preview`) are optional in `SiteConfig`: an omitted plugin does not supply defaults or validate its unused input. A replacement plugin reads its settings from `input` and `file`, then contributes normalized config. Analytics also resolves explicitly configured consent when its browser runtime is omitted, so enabled consent is never bypassed. Configuration contributions are synchronous and may run whenever a project configuration is resolved; keep file writes and other side effects in lifecycle hooks.
179
238
180
239
Builder style state is isolated across asynchronous operations, including concurrent sites. Its owned theme options remain linked to `context.config.style.theme`, so in-place config-hook changes and `themes.setOptions` update page colors, CSS, and generated favicons consistently. Head, metadata, template, Markdown, provider, and lifecycle errors identify their owning plugin and preserve the original cause. Markdown wrappers preserve unified presets, duplicate-plugin option merging, and callback transforms.
0 commit comments