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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrap @sveltejs/adapter-static #29

Merged
merged 1 commit into from
Feb 26, 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
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export default {
fallback: null,
precompress: false,
manifest: "manifest.json",
emptyOutDir: true,
}),
appDir: "app",
},
Expand Down Expand Up @@ -53,12 +52,6 @@ If `true`, precompresses files with brotli and gzip. This will generate `.br` an
Specify manifest file name if you want different manifests for different target platforms, e.g. `chrome_manifest.json`, `firefox_manifest.json`.
This file name must match one that is present in the `static` directory (the dir containing your static files). The selected target file will be renamed to `manifest.json` in the build directory, and all other `.json` files with `manifest` in the name won't be copied.


### emptyOutDir

Specify if the output directory should automatically be emptied when building the project. Defaults to `true`.
Turn to `false` if you use alternate watch commands for which emptying the output directory may create conflicts.

## License

[MIT](LICENSE)
42 changes: 7 additions & 35 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import staticAdapter from '@sveltejs/adapter-static';
import { load } from "cheerio";
import {
createReadStream,
Expand All @@ -17,47 +18,18 @@ import zlib from "zlib";
const pipe = promisify(pipeline);

/** @type {import('.')} */
export default function ({
pages = "build",
assets = pages,
fallback,
precompress = false,
manifest = "manifest.json",
emptyOutDir = true,
} = {}) {
export default function (options) {
return {
name: "sveltekit-adapter-chrome-extension",

async adapt(builder) {
if (emptyOutDir) {
builder.rimraf(assets);
builder.rimraf(pages);
}

builder.writeClient(assets);

builder.writePrerendered(pages, { fallback });

if (precompress) {
if (pages === assets) {
builder.log.minor("Compressing assets and pages");
await compress(assets);
} else {
builder.log.minor("Compressing assets");
await compress(assets);

builder.log.minor("Compressing pages");
await compress(pages);
}
}

if (pages === assets) {
builder.log(`Wrote site to "${pages}"`);
} else {
builder.log(`Wrote pages to "${pages}" and assets to "${assets}"`);
}
staticAdapter(options).adapt(builder);

/* extension */
const pages = options?.pages ?? "build";
const assets = options?.assets ?? pages;
const manifest = options?.manifest ?? "manifest.json";

await removeInlineScripts(assets, builder.log);

await removeAppManifest(assets, builder.config.kit.appDir, builder.log);
Expand Down
Loading