From b575070962ff3b0c67da78a4c2bb739e62afce27 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Mon, 14 Oct 2019 19:48:23 +0800 Subject: [PATCH 1/2] feat: Allow bundling of all modules, except those specified --- lib/config/webpack.server.ts | 11 ++++++++++- lib/runtime/server.ts | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/config/webpack.server.ts b/lib/config/webpack.server.ts index ef21fb9a..353da890 100644 --- a/lib/config/webpack.server.ts +++ b/lib/config/webpack.server.ts @@ -40,8 +40,17 @@ const serverBaseConfig = (options: CreateWebpackConfigOptions): webpack.Configur // treat deep imports as externals as well const moduleName = request.split('/')[0] - if (options.buildConfig.SERVER_BUNDLE_ALL) { + if ( + options.buildConfig.SERVER_BUNDLE_ALL && + !options.buildConfig.SERVER_BUNDLE_ALL_EXCEPT + ) { callback(undefined, undefined) + } else if (options.buildConfig.SERVER_BUNDLE_ALL_EXCEPT) { + if (options.buildConfig.SERVER_BUNDLE_ALL_EXCEPT.indexOf(moduleName) !== -1) { + callback(null, 'commonjs ' + request) + } else { + callback(undefined, undefined) + } } else if (options.buildConfig.SERVER_INCLUDE_IN_BUNDLE.indexOf(moduleName) !== -1) { callback(undefined, undefined) } else if (nodeModules.indexOf(moduleName) !== -1) { diff --git a/lib/runtime/server.ts b/lib/runtime/server.ts index 36426273..aa23fc82 100644 --- a/lib/runtime/server.ts +++ b/lib/runtime/server.ts @@ -65,6 +65,9 @@ export interface BuildConfig { /** if true, all externals will be bundled */ SERVER_BUNDLE_ALL: boolean + /** Include all modules, except a blacklist */ + SERVER_BUNDLE_ALL_EXCEPT?: string[] + /** modules which the server build includes in the bundle */ SERVER_INCLUDE_IN_BUNDLE: string[] From 5347ad6b7c15a2042b2b2790cb515f1cd9f61c58 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Mon, 14 Oct 2019 19:55:25 +0800 Subject: [PATCH 2/2] Improved docs --- docs/config.md | 3 +++ lib/runtime/server.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/config.md b/docs/config.md index 1b3b5cbb..145664d8 100644 --- a/docs/config.md +++ b/docs/config.md @@ -97,6 +97,9 @@ export interface BuildConfig { /** if true, all externals will be bundled */ SERVER_BUNDLE_ALL: boolean + /** Include all modules, except those specified */ + SERVER_BUNDLE_ALL_EXCEPT?: string[] + /** modules which the server build includes in the bundle */ SERVER_INCLUDE_IN_BUNDLE: string[] diff --git a/lib/runtime/server.ts b/lib/runtime/server.ts index aa23fc82..e48c3a13 100644 --- a/lib/runtime/server.ts +++ b/lib/runtime/server.ts @@ -65,7 +65,7 @@ export interface BuildConfig { /** if true, all externals will be bundled */ SERVER_BUNDLE_ALL: boolean - /** Include all modules, except a blacklist */ + /** Include all modules, except those specified */ SERVER_BUNDLE_ALL_EXCEPT?: string[] /** modules which the server build includes in the bundle */