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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not include api server plugin for production builds #275

Merged
merged 5 commits into from
Oct 22, 2021
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
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# changelog

## 0.44.1

- change default config to not run the api server during build
([#275](https://github.com/feltcoop/gro/pull/275))

## 0.44.0

- **break**: upgrade `@feltcoop/felt@0.13.0` and make it a peer dependency
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions src/adapt/groAdapterSveltekitFrontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ export interface Options {
dir: string;
sveltekitDir: string;
hostTarget: HostTarget;
deploymentMode: 'server' | 'middleware' | 'both'; // TODO hacky option that works around `@sveltejs/adapter-node`'s lack of configurable outputs
}

// TODO this hacks around the fact that we don't create a proper Gro build for SvelteKit frontends
export const createAdapter = ({
dir = `${DIST_DIRNAME}/${SVELTEKIT_DIST_DIRNAME}`,
sveltekitDir = SVELTEKIT_BUILD_DIRNAME,
hostTarget = 'githubPages',
deploymentMode = 'middleware',
}: Partial<Options> = EMPTY_OBJECT): Adapter => {
dir = stripTrailingSlash(dir);
return {
Expand All @@ -26,8 +28,19 @@ export const createAdapter = ({

await fs.copy(sveltekitDir, dir);

if (hostTarget === 'githubPages') {
await ensureNojekyll(fs, dir);
switch (hostTarget) {
case 'githubPages': {
await ensureNojekyll(fs, dir);
break;
}
case 'node': {
if (deploymentMode === 'middleware') {
await fs.remove(`${dir}/index.js`);
} else if (deploymentMode === 'server') {
await fs.remove(`${dir}/middlewares.js`);
}
break;
}
}
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/adapt/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const copyDist = async (
);
};

export type HostTarget = 'githubPages' | 'static';
export type HostTarget = 'githubPages' | 'static' | 'node';

const NOJEKYLL_FILENAME = '.nojekyll';

Expand Down
11 changes: 9 additions & 2 deletions src/config/gro.config.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ export const config: GroConfigCreator = async ({fs, dev}) => {
types: enableNodeLibrary,
plugin: async () => [
enableDevServer ? (await import('../plugin/groPluginDevServer.js')).createPlugin() : null,
enableApiServer ? (await import('../plugin/groPluginApiServer.js')).createPlugin() : null,
// TODO some usecases may need to run the API server during the build for e.g. prerendering,
// but it's currently disabled because the adapter-node usecase has the production API server
// depend on the middleware created later in the adapt step of the build
enableApiServer && dev
? (await import('../plugin/groPluginApiServer.js')).createPlugin()
: null,
enableSveltekitFrontend
? (await import('../plugin/groPluginSveltekitFrontend.js')).createPlugin()
: null,
Expand All @@ -66,7 +71,9 @@ export const config: GroConfigCreator = async ({fs, dev}) => {
? (await import('../adapt/groAdapterGroFrontend.js')).createAdapter()
: null,
enableSveltekitFrontend
? (await import('../adapt/groAdapterSveltekitFrontend.js')).createAdapter()
? (await import('../adapt/groAdapterSveltekitFrontend.js')).createAdapter({
hostTarget: enableApiServer ? 'node' : 'githubPages',
})
: null,
],
};
Expand Down