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/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..e48c3a13 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 those specified */ + SERVER_BUNDLE_ALL_EXCEPT?: string[] + /** modules which the server build includes in the bundle */ SERVER_INCLUDE_IN_BUNDLE: string[]