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

auto detect netlify build #465

Merged
merged 5 commits into from
Feb 10, 2024
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
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,27 @@ Adding the `--with-vercel-static` flag to the build script will produce static s
}
```

### Netlify Deploy

Waku projects can be deployed to Netlify with the [Netlify CLI](https://docs.netlify.com/cli/get-started/).

```
npm run build -- --with-netlify
netlify deploy --dir=dist/public
```

#### Pure SSG

Adding the `--with-netlify-static` flag to the build script will produce static sites without Netlify functions.

```
{
"scripts": {
"build": "waku build --with-ssr --with-netlify-static"
}
}
```

### Cloudflare (experimental)

```
Expand All @@ -661,13 +682,6 @@ npm run build -- --with-deno
DENO_DEPLOY_TOKEN=... deployctl deploy --project=... --prod dist/serve.js --exclude node_modules
```

### Netlify Deploy (experimental)

```
npm run build -- --with-netlify
netlify deploy
```

### AWS Lambda (experimental)

```
Expand Down
2 changes: 1 addition & 1 deletion packages/waku/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async function runBuild(options: { ssr: boolean }) {
: undefined) ||
(values['with-cloudflare'] ? 'cloudflare' : undefined) ||
(values['with-deno'] ? 'deno' : undefined) ||
(values['with-netlify']
(values['with-netlify'] ?? !!process.env.NETLIFY
? values['with-netlify-static']
? 'netlify-static'
: 'netlify-functions'
Expand Down
22 changes: 3 additions & 19 deletions packages/waku/src/lib/builder/output-netlify.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'node:path';
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
import { mkdirSync, writeFileSync } from 'node:fs';

import type { ResolvedConfig } from '../config.js';

Expand All @@ -9,35 +9,19 @@ export const emitNetlifyOutput = async (
type: 'static' | 'functions',
) => {
if (type === 'functions') {
const functionsDir = path.join(rootDir, 'functions');
const functionsDir = path.join(rootDir, 'netlify/functions');
mkdirSync(functionsDir, {
recursive: true,
});
writeFileSync(
path.join(functionsDir, 'serve.js'),
`
export { default } from '../${config.distDir}/${config.serveJs}';
export { default } from '../../${config.distDir}/${config.serveJs}';
export const config = {
preferStatic: true,
path: ['/', '/*'],
};
`,
);
}
const netlifyTomlFile = path.join(rootDir, 'netlify.toml');
if (!existsSync(netlifyTomlFile)) {
writeFileSync(
netlifyTomlFile,
`
[build]
publish = "${config.distDir}/${config.publicDir}"
` +
(type === 'functions'
? `
[functions]
directory = "functions"
`
: ''),
);
}
};
Loading