Skip to content

Commit

Permalink
fix: exclude server files from optimizeDeps.entries (#12242)
Browse files Browse the repository at this point in the history
* exclude server files from optimizeDeps.entries

* fix glob to exclude +server.js and fix tests

* changeset

* Revert "fix glob to exclude +server.js and fix tests"

This reverts commit c778f78.

* review suggestions

* remove dot

* Update index.js

---------

Co-authored-by: Simon H <[email protected]>
  • Loading branch information
gtm-nayan and dummdidumm authored May 21, 2024
1 parent 119bff9 commit 460d452
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-hairs-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/kit": patch
---

fix: exclude server files from optimizeDeps.entries
5 changes: 4 additions & 1 deletion packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,10 @@ async function kit({ svelte_config }) {
cors: { preflightContinue: true }
},
optimizeDeps: {
entries: [`${kit.files.routes}/**/+*.{svelte,js,ts}`],
entries: [
`${kit.files.routes}/**/+*.{svelte,js,ts}`,
`!${kit.files.routes}/**/+*server.*`
],
exclude: [
'@sveltejs/kit',
// exclude kit features so that libraries using them work even when they are prebundled
Expand Down
8 changes: 4 additions & 4 deletions packages/kit/test/apps/dev-only/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ test.describe('Vite', () => {
expect(manifest).toHaveProperty('optimized.e2e-test-dep-page-universal');
});

test('optimizes +page.server.js dependencies', async ({ page }) => {
test('skips optimizing +page.server.js dependencies', async ({ page }) => {
await page.goto('/');
await page.getByText('hello world!').waitFor();

const manifest_path = path.join(__dirname, '../node_modules/.vite/deps/_metadata.json');
const manifest = JSON.parse(fs.readFileSync(manifest_path, 'utf-8'));

expect(manifest).toHaveProperty('optimized.e2e-test-dep-page-server');
expect(manifest).not.toHaveProperty('optimized.e2e-test-dep-page-server');
});

test('optimizes +layout.svelte dependencies', async ({ page }) => {
Expand All @@ -137,14 +137,14 @@ test.describe('Vite', () => {
expect(manifest).toHaveProperty('optimized.e2e-test-dep-layout-universal');
});

test('optimizes +layout.server.js dependencies', async ({ page }) => {
test('skips optimizing +layout.server.js dependencies', async ({ page }) => {
await page.goto('/');
await page.getByText('hello world!').waitFor();

const manifest_path = path.join(__dirname, '../node_modules/.vite/deps/_metadata.json');
const manifest = JSON.parse(fs.readFileSync(manifest_path, 'utf-8'));

expect(manifest).toHaveProperty('optimized.e2e-test-dep-layout-server');
expect(manifest).not.toHaveProperty('optimized.e2e-test-dep-layout-server');
});

test('optimizes +error.svelte dependencies', async ({ page }) => {
Expand Down

0 comments on commit 460d452

Please sign in to comment.