From 0fa09f53fb30f58fbf925b1b23e36a7df420a1f4 Mon Sep 17 00:00:00 2001 From: Dylan Piercey Date: Wed, 11 Mar 2020 11:32:41 -0700 Subject: [PATCH] fix: do not load browser.json files by default --- src/loader/index.ts | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/loader/index.ts b/src/loader/index.ts index 7e03dd4..4374360 100644 --- a/src/loader/index.ts +++ b/src/loader/index.ts @@ -154,27 +154,31 @@ export default function(source: string): string { if (meta.deps) { dependencies = dependencies.concat( - meta.deps.map(dependency => { - if (!dependency.code) { - if ( - supportsBrowserJSON && - dependency.startsWith(browserJSONPrefix) - ) { - dependency = dependency.slice(browserJSONPrefix.length); + meta.deps + .map(dependency => { + if (!dependency.code) { + if (dependency.startsWith(browserJSONPrefix)) { + if (supportsBrowserJSON) { + dependency = dependency.slice(browserJSONPrefix.length); + } else { + return ""; // Do not load browser.json dependencies by default. + } + } + + // external file, just require it + return loadStr(dependency); + } else { + // inline content, we'll create a virtual dependency. + const virtualPath = path.resolve( + path.dirname(this.resourcePath), + dependency.virtualPath + ); + const virtualModules = getVirtualModules(this._compiler); + virtualModules.writeModule(virtualPath, dependency.code); + return loadStr(dependency.virtualPath); } - // external file, just require it - return loadStr(dependency); - } else { - // inline content, we'll create a virtual dependency. - const virtualPath = path.resolve( - path.dirname(this.resourcePath), - dependency.virtualPath - ); - const virtualModules = getVirtualModules(this._compiler); - virtualModules.writeModule(virtualPath, dependency.code); - return loadStr(dependency.virtualPath); - } - }) + }) + .filter(Boolean) ); }