-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@astrojs/netlify): add
build.split
support (#7615)
Co-authored-by: Sarah Rainsberger <[email protected]> Co-authored-by: Bjorn Lu <[email protected]>
- Loading branch information
1 parent
b30a1bc
commit f21357b
Showing
20 changed files
with
234 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
'@astrojs/netlify': minor | ||
--- | ||
|
||
The Netlify adapter builds to a single function by default. Astro 2.7 added support for splitting your build into separate entry points per page. If you use this configuration, the Netlify adapter will generate a separate function for each page. This can help reduce the size of each function so they are only bundling code used on that page. | ||
|
||
|
||
```js | ||
// astro.config.mjs | ||
import { defineConfig } from 'astro/config'; | ||
import netlify from '@astrojs/netlify/functions'; | ||
|
||
export default defineConfig({ | ||
output: 'server', | ||
adapter: netlify(), | ||
build: { | ||
split: true, | ||
}, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/underscore-redirects': minor | ||
--- | ||
|
||
Refactor how the routes are passed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/integrations/netlify/test/functions/fixtures/prerender/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
<html> | ||
<head> | ||
<title>Testing</title> | ||
<title>Blog</title> | ||
</head> | ||
<body> | ||
<h1>testing</h1> | ||
<h1>Blog</h1> | ||
</body> | ||
</html> |
8 changes: 8 additions & 0 deletions
8
packages/integrations/netlify/test/functions/fixtures/split-support/src/pages/blog.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<title>Testing</title> | ||
</head> | ||
<body> | ||
<h1>testing</h1> | ||
</body> | ||
</html> |
8 changes: 8 additions & 0 deletions
8
packages/integrations/netlify/test/functions/fixtures/split-support/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<title>Blog</title> | ||
</head> | ||
<body> | ||
<h1>Blog</h1> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/integrations/netlify/test/functions/redirects.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`SSG - Redirects Creates a redirects file 1`] = ` | ||
"/other / 301 | ||
/nope /.netlify/functions/entry 200 | ||
/ /.netlify/functions/entry 200 | ||
/team/articles/* /.netlify/functions/entry 200" | ||
`; |
63 changes: 63 additions & 0 deletions
63
packages/integrations/netlify/test/functions/split-support.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { expect } from 'chai'; | ||
import netlifyAdapter from '../../dist/index.js'; | ||
import { loadFixture, testIntegration } from './test-utils.js'; | ||
|
||
describe('Split support', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
let _entryPoints; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: new URL('./fixtures/split-support/', import.meta.url).toString(), | ||
output: 'server', | ||
adapter: netlifyAdapter({ | ||
dist: new URL('./fixtures/split-support/dist/', import.meta.url), | ||
}), | ||
site: `http://example.com`, | ||
integrations: [ | ||
testIntegration({ | ||
setEntryPoints(ep) { | ||
_entryPoints = ep; | ||
}, | ||
}), | ||
], | ||
build: { | ||
split: true, | ||
}, | ||
}); | ||
await fixture.build(); | ||
}); | ||
|
||
it('outputs a correct redirect file', async () => { | ||
const redir = await fixture.readFile('/_redirects'); | ||
const lines = redir.split(/[\r\n]+/); | ||
expect(lines.length).to.equal(2); | ||
|
||
expect(lines[0].includes('/blog')).to.be.true; | ||
expect(lines[0].includes('blog.astro')).to.be.true; | ||
expect(lines[0].includes('200')).to.be.true; | ||
expect(lines[1].includes('/')).to.be.true; | ||
expect(lines[1].includes('index.astro')).to.be.true; | ||
expect(lines[1].includes('200')).to.be.true; | ||
}); | ||
|
||
describe('Should create multiple functions', () => { | ||
it('and hit 200', async () => { | ||
if (_entryPoints) { | ||
for (const [, filePath] of _entryPoints) { | ||
const { handler } = await import(filePath.toString()); | ||
const resp = await handler({ | ||
httpMethod: 'POST', | ||
headers: {}, | ||
rawUrl: 'http://example.com/', | ||
body: '{}', | ||
}); | ||
expect(resp.statusCode).to.equal(200); | ||
} | ||
} else { | ||
expect(false).to.be.true; | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { use } from 'chai'; | ||
import chaiJestSnapshot from 'chai-jest-snapshot'; | ||
|
||
use(chaiJestSnapshot); | ||
|
||
before(function () { | ||
chaiJestSnapshot.resetSnapshotRegistry(); | ||
}); | ||
|
||
beforeEach(function () { | ||
chaiJestSnapshot.configureUsingMochaContext(this); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.