Skip to content

Commit c4410c5

Browse files
authored
[Fix] adapter API breaking changes (#9)
* Adapt to adapter API changes introduced by #4192 * Modify readme to reflect newly required config boilerplate
1 parent 578d872 commit c4410c5

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
## Usage
66

7-
Install with `npm i -D sveltekit-adapter-browser-extension`, then add the adapter to your `svelte.config.js`, and set the appDir to something without an underscore:
7+
Install with `npm i -D sveltekit-adapter-browser-extension`, then add the adapter to your `svelte.config.js`.
8+
9+
Some additional configuration is required for this adapter to work - you need to (1) set ``appDir`` to something without an underscore and (2) tell kit to prerender its pages by default:
810

911
```js
1012
// svelte.config.js
@@ -13,7 +15,10 @@ import adapter from 'sveltekit-adapter-browser-extension';
1315
export default {
1416
kit: {
1517
adapter: adapter(),
16-
appDir: 'ext' // This is important - chrome extensions can't handle the default _app directory name.
18+
appDir: 'ext', // This is important - chrome extensions can't handle the default _app directory name.
19+
prerender: {
20+
default: true
21+
}
1722
}
1823
};
1924
```

adapter-browser-extension.mjs

+16-12
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,29 @@ function load_manifest () {
4242
return {}
4343
}
4444

45+
4546
/** @type {import('.')} */
4647
export default function ({ pages = 'build', assets = pages, fallback } = {}) {
4748
return {
4849
name: 'sveltekit-adapter-browser-extension',
4950

50-
async adapt({ utils }) {
51+
async adapt(builder) {
52+
if (!fallback && !builder.config.kit.prerender.default) {
53+
builder.log.warn(
54+
'You should set `config.kit.prerender.default` to `true` if no fallback is specified'
55+
);
56+
}
57+
58+
5159
const provided_manifest = load_manifest()
5260

53-
utils.rimraf(assets)
54-
utils.rimraf(pages)
61+
builder.rimraf(assets)
62+
builder.rimraf(pages)
5563

56-
utils.copy_static_files(assets)
57-
utils.copy_client_files(assets)
64+
builder.writeStatic(assets)
65+
builder.writeClient(assets)
5866

59-
await utils.prerender({
60-
fallback,
61-
all: !fallback,
62-
dest: pages
63-
})
67+
builder.writePrerendered(pages, { fallback });
6468

6569
const index_page = join(assets, 'index.html')
6670
const index = readFileSync(index_page)
@@ -69,7 +73,7 @@ export default function ({ pages = 'build', assets = pages, fallback } = {}) {
6973
const merged_manifest = applyToDefaults(generated_manifest, provided_manifest, { nullOverride: true })
7074

7175
writeFileSync(join(assets, manifest_filename), JSON.stringify(merged_manifest))
72-
utils.rimraf(join(assets, '_app'))
76+
builder.rimraf(join(assets, '_app'))
7377
}
7478
}
75-
}
79+
}

0 commit comments

Comments
 (0)