From eb14eca702ccfc8abca6ea00c94ecc72bba0878b Mon Sep 17 00:00:00 2001 From: Ahad Birang Date: Mon, 17 Jan 2022 20:55:26 +0330 Subject: [PATCH] fix(nitro): allow inlining subpath of externals (#2759) --- packages/nitro/src/rollup/plugins/externals.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/nitro/src/rollup/plugins/externals.ts b/packages/nitro/src/rollup/plugins/externals.ts index abd59fd3dc..fd019dc40e 100644 --- a/packages/nitro/src/rollup/plugins/externals.ts +++ b/packages/nitro/src/rollup/plugins/externals.ts @@ -39,8 +39,9 @@ export function externals (opts: NodeExternalsOptions): Plugin { // Normalize from node_modules const _id = id.split('node_modules/').pop() + const externalPath = opts.external.find(i => _id.startsWith(i) || id.startsWith(i)) // Skip checks if is an explicit external - if (!opts.external.find(i => _id.startsWith(i) || id.startsWith(i))) { + if (!externalPath) { // Resolve relative paths and exceptions // Ensure to take absolute and relative id if (_id.startsWith('.') || opts.inline.find(i => _id.startsWith(i) || id.startsWith(i))) { @@ -50,6 +51,9 @@ export function externals (opts: NodeExternalsOptions): Plugin { if (/\.(ts|wasm|json)$/.test(_id)) { return null } + // Check for subpaths + } else if (opts.inline.find(i => i.startsWith(externalPath) && (_id.startsWith(i) || id.startsWith(i)))) { + return null } // Track externals