diff --git a/package.json b/package.json index 36a2dc4fb..435578589 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "private": true, "scripts": { "release": "yarn build && yarn changeset publish", + "benchmark": "yarn workspace astro run benchmark", "build": "yarn build:core", "build:core": "lerna run build --scope astro --scope astro-parser", "build:vscode": "lerna run build --scope astro-languageserver --scope astro-vscode --scope astro-parser", diff --git a/packages/astro/src/external.ts b/packages/astro/src/external.ts new file mode 100644 index 000000000..7a77f7aa3 --- /dev/null +++ b/packages/astro/src/external.ts @@ -0,0 +1,42 @@ +import { createRequire } from 'module'; +const require = createRequire(import.meta.url); +const pkg = require('../package.json'); + +/** + * This file allows us to automatically exclude + * particular packages from Snowpack's `esinstall` + * step. + */ + +// These packages SHOULD be built by `esinstall` +const allowList = new Set([ + 'astro-prism', + 'prismjs', + 'shorthash' +]); + +const isAstroRenderer = (name: string) => { + return name.startsWith(`@astrojs/renderer-`); +} + +// These packages should NOT be built by `esinstall` +// But might not be explicit dependencies of `astro` +const denyList = [ + 'prismjs/components/index.js', + '@vue/server-renderer' +]; + + +export default Object.keys(pkg.dependencies) + // Filter out packages that should be loaded threw Snowpack + .filter(name => { + // Explicitly allowed packages should NOT be external + if (allowList.has(name)) return false; + // Astro renderers should NOT be external + if (isAstroRenderer(name)) return false; + // Everything else SHOULD be external + return true; + }) + // Add extras + .concat(denyList) + .sort(); diff --git a/packages/astro/src/runtime.ts b/packages/astro/src/runtime.ts index 40d4f5f8b..55f38505b 100644 --- a/packages/astro/src/runtime.ts +++ b/packages/astro/src/runtime.ts @@ -13,6 +13,7 @@ import { loadConfiguration, logger as snowpackLogger, startServer as startSnowpa import { canonicalURL, stopTimer } from './build/util.js'; import { debug, info } from './logger.js'; import { searchForPage } from './search.js'; +import snowpackExternals from './external.js'; interface RuntimeConfig { astroConfig: AstroConfig; @@ -374,7 +375,7 @@ async function createSnowpack(astroConfig: AstroConfig, options: CreateSnowpackO }, packageOptions: { knownEntrypoints, - external: ['@vue/server-renderer', 'node-fetch', 'prismjs/components/index.js', 'gray-matter'], + external: snowpackExternals, }, }); diff --git a/packages/astro/test/benchmark/build-cached.json b/packages/astro/test/benchmark/build-cached.json index 2ddc47c7c..57f8ad38f 100644 --- a/packages/astro/test/benchmark/build-cached.json +++ b/packages/astro/test/benchmark/build-cached.json @@ -1,4 +1,4 @@ { "name": "Snowpack Example Build Cached", - "time": 10484 -} + "time": 8496 +} \ No newline at end of file diff --git a/packages/astro/test/benchmark/build-uncached.json b/packages/astro/test/benchmark/build-uncached.json index ca4f2524a..d7976d926 100644 --- a/packages/astro/test/benchmark/build-uncached.json +++ b/packages/astro/test/benchmark/build-uncached.json @@ -1,4 +1,4 @@ { "name": "Snowpack Example Build Uncached", - "time": 19629 -} + "time": 16200 +} \ No newline at end of file diff --git a/packages/astro/test/benchmark/dev-server-cached.json b/packages/astro/test/benchmark/dev-server-cached.json index e05ffc14c..e28cc05f4 100644 --- a/packages/astro/test/benchmark/dev-server-cached.json +++ b/packages/astro/test/benchmark/dev-server-cached.json @@ -1,4 +1,4 @@ { "name": "Snowpack Example Dev Server Cached", - "time": 1868 -} + "time": 1229 +} \ No newline at end of file diff --git a/packages/astro/test/benchmark/dev-server-uncached.json b/packages/astro/test/benchmark/dev-server-uncached.json index 71601029a..b86393f98 100644 --- a/packages/astro/test/benchmark/dev-server-uncached.json +++ b/packages/astro/test/benchmark/dev-server-uncached.json @@ -1,4 +1,4 @@ { "name": "Snowpack Example Dev Server Uncached", - "time": 9803 -} + "time": 3913 +} \ No newline at end of file