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

Prevent bundling sharp #8196

Merged
merged 1 commit into from
Aug 23, 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
5 changes: 5 additions & 0 deletions .changeset/spicy-stingrays-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Prevent bundling sharp as it errors in runtime
25 changes: 13 additions & 12 deletions packages/astro/src/core/build/plugins/plugin-internals.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UserConfig, Plugin as VitePlugin } from 'vite';
import type { Plugin as VitePlugin } from 'vite';
import type { BuildInternals } from '../internal.js';
import type { AstroBuildPlugin } from '../plugin';
import { normalizeEntryId } from './plugin-component-entry.js';
Expand All @@ -8,19 +8,20 @@ export function vitePluginInternals(input: Set<string>, internals: BuildInternal
name: '@astro/plugin-build-internals',

config(config, options) {
const extra: Partial<UserConfig> = {};
const noExternal = [],
external = [];
if (options.command === 'build' && config.build?.ssr) {
noExternal.push('astro');
external.push('shiki');
return {
ssr: {
// Always bundle Astro runtime when building for SSR
noExternal: ['astro'],
// Except for these packages as they're not bundle-friendly. Users with strict package installations
// need to manually install these themselves if they use the related features.
external: [
'shiki', // For syntax highlighting
'sharp', // For sharp image service
],
},
};
}

extra.ssr = {
external,
noExternal,
};
return extra;
},

async generateBundle(_options, bundle) {
Expand Down
Loading