@@ -11,8 +11,8 @@ import { WebpackConfigOptions } from '../build-options';
11
11
import { getSourceMapDevTool } from './utils' ;
12
12
13
13
/**
14
- * Returns a partial specific to creating a bundle for node
15
- * @param wco Options which are include the build options and app config
14
+ * Returns a partial Webpack configuration specific to creating a bundle for node
15
+ * @param wco Options which include the build options and app config
16
16
*/
17
17
export function getServerConfig ( wco : WebpackConfigOptions ) : Configuration {
18
18
const {
@@ -22,11 +22,14 @@ export function getServerConfig(wco: WebpackConfigOptions): Configuration {
22
22
} = wco . buildOptions ;
23
23
24
24
const extraPlugins = [ ] ;
25
- if ( sourceMap ) {
26
- const { scripts, styles, hidden } = sourceMap ;
27
- if ( scripts || styles ) {
28
- extraPlugins . push ( getSourceMapDevTool ( scripts , styles , hidden ) ) ;
29
- }
25
+ const { scripts, styles, hidden } = sourceMap ;
26
+ if ( scripts || styles ) {
27
+ extraPlugins . push ( getSourceMapDevTool ( scripts , styles , hidden ) ) ;
28
+ }
29
+
30
+ const externals : Configuration [ 'externals' ] = [ ...externalDependencies ] ;
31
+ if ( ! bundleDependencies ) {
32
+ externals . push ( externalizePackages ) ;
30
33
}
31
34
32
35
const config : Configuration = {
@@ -44,31 +47,29 @@ export function getServerConfig(wco: WebpackConfigOptions): Configuration {
44
47
...extraPlugins ,
45
48
] ,
46
49
node : false ,
50
+ externals,
47
51
} ;
48
52
49
- if ( bundleDependencies ) {
50
- config . externals = [ ...externalDependencies ] ;
51
- } else {
52
- config . externals = [
53
- ...externalDependencies ,
54
- ( context : string , request : string , callback : ( error ?: null , result ?: string ) => void ) => {
55
- // Absolute & Relative paths are not externals
56
- if ( request . startsWith ( '.' ) || isAbsolute ( request ) ) {
57
- callback ( ) ;
53
+ return config ;
54
+ }
58
55
59
- return ;
60
- }
56
+ function externalizePackages (
57
+ context : string ,
58
+ request : string ,
59
+ callback : ( error ?: Error , result ?: string ) => void ,
60
+ ) : void {
61
+ // Absolute & Relative paths are not externals
62
+ if ( request . startsWith ( '.' ) || isAbsolute ( request ) ) {
63
+ callback ( ) ;
61
64
62
- try {
63
- require . resolve ( request ) ;
64
- callback ( null , request ) ;
65
- } catch {
66
- // Node couldn't find it, so it must be user-aliased
67
- callback ( ) ;
68
- }
69
- } ,
70
- ] ;
65
+ return ;
71
66
}
72
67
73
- return config ;
68
+ try {
69
+ require . resolve ( request , { paths : [ context ] } ) ;
70
+ callback ( undefined , request ) ;
71
+ } catch {
72
+ // Node couldn't find it, so it must be user-aliased
73
+ callback ( ) ;
74
+ }
74
75
}
0 commit comments