From 846cfee1708dd6610d4a20fe80775ad144db3a3f Mon Sep 17 00:00:00 2001 From: Johannes Lamberts Date: Tue, 9 Jun 2020 18:40:39 +0200 Subject: [PATCH] fix(webpack): reduce false negatives in nodeExternals (#7462) (#7464) --- packages/webpack/src/config/server.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/webpack/src/config/server.js b/packages/webpack/src/config/server.js index 9f8b9f876e..d921c43304 100644 --- a/packages/webpack/src/config/server.js +++ b/packages/webpack/src/config/server.js @@ -7,6 +7,11 @@ import VueSSRServerPlugin from '../plugins/vue/server' import WebpackBaseConfig from './base' +const nativeFileExtensions = [ + '.json', + '.js' +] + export default class WebpackServerConfig extends WebpackBaseConfig { constructor (...args) { super(...args) @@ -20,11 +25,23 @@ export default class WebpackServerConfig extends WebpackBaseConfig { get externalsWhitelist () { return [ - /\.(?!js(x|on)?$)/i, + this.isNonNativeImport.bind(this), ...this.normalizeTranspile() ] } + /** + * files *not* ending on js|json should be processed by webpack + * + * this might generate false-positives for imports like + * - "someFile.umd" (actually requiring someFile.umd.js) + * - "some.folder" (some.folder being a directory containing a package.json) + */ + isNonNativeImport (modulePath) { + const extname = path.extname(modulePath) + return extname !== '' && !nativeFileExtensions.includes(extname) + } + env () { return Object.assign( super.env(),