Improve dev perf by not esinstalling Node deps (#253)
* Improve dev startup by making most dependencies externals This moves most dependencies to be an `external` for Snowpack, preventing backend deps from going through esinstall. * Update benchmark times * chore: add benchmark script for convenience * fix: update externals to allow renderers * chore: update benchmark times Co-authored-by: Nate Moore <nate@skypack.dev>
This commit is contained in:
parent
94a053c99c
commit
f49944c0e7
7 changed files with 53 additions and 9 deletions
|
@ -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",
|
||||
|
|
42
packages/astro/src/external.ts
Normal file
42
packages/astro/src/external.ts
Normal file
|
@ -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();
|
|
@ -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,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"name": "Snowpack Example Build Cached",
|
||||
"time": 10484
|
||||
"time": 8496
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"name": "Snowpack Example Build Uncached",
|
||||
"time": 19629
|
||||
"time": 16200
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"name": "Snowpack Example Dev Server Cached",
|
||||
"time": 1868
|
||||
"time": 1229
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"name": "Snowpack Example Dev Server Uncached",
|
||||
"time": 9803
|
||||
"time": 3913
|
||||
}
|
Loading…
Reference in a new issue