@@ -17,36 +17,40 @@ function addEntries(config, options, server) {
17
17
18
18
const domain = createDomain ( options , app ) ;
19
19
const sockPath = options . sockPath ? `&sockPath=${ options . sockPath } ` : '' ;
20
- const entries = [
21
- `${ require . resolve ( '../../client/' ) } ?${ domain } ${ sockPath } ` ,
22
- ] ;
20
+ const clientEntry = `${ require . resolve (
21
+ '../../client/'
22
+ ) } ?${ domain } ${ sockPath } `;
23
+ let hotEntry ;
23
24
24
25
if ( options . hotOnly ) {
25
- entries . push ( require . resolve ( 'webpack/hot/only-dev-server' ) ) ;
26
+ hotEntry = require . resolve ( 'webpack/hot/only-dev-server' ) ;
26
27
} else if ( options . hot ) {
27
- entries . push ( require . resolve ( 'webpack/hot/dev-server' ) ) ;
28
+ hotEntry = require . resolve ( 'webpack/hot/dev-server' ) ;
28
29
}
29
30
30
- const prependEntry = ( entry ) => {
31
- if ( typeof entry === 'function' ) {
32
- return ( ) => Promise . resolve ( entry ( ) ) . then ( prependEntry ) ;
31
+ const prependEntry = ( originalEntry , additionalEntries ) => {
32
+ if ( typeof originalEntry === 'function' ) {
33
+ return ( ) =>
34
+ Promise . resolve ( originalEntry ( ) ) . then ( ( entry ) =>
35
+ prependEntry ( entry , additionalEntries )
36
+ ) ;
33
37
}
34
38
35
- if ( typeof entry === 'object' && ! Array . isArray ( entry ) ) {
39
+ if ( typeof originalEntry === 'object' && ! Array . isArray ( originalEntry ) ) {
36
40
const clone = { } ;
37
41
38
- Object . keys ( entry ) . forEach ( ( key ) => {
42
+ Object . keys ( originalEntry ) . forEach ( ( key ) => {
39
43
// entry[key] should be a string here
40
- clone [ key ] = prependEntry ( entry [ key ] ) ;
44
+ clone [ key ] = prependEntry ( originalEntry [ key ] , additionalEntries ) ;
41
45
} ) ;
42
46
43
47
return clone ;
44
48
}
45
49
46
50
// in this case, entry is a string or an array.
47
51
// make sure that we do not add duplicates.
48
- const entriesClone = entries . slice ( 0 ) ;
49
- [ ] . concat ( entry ) . forEach ( ( newEntry ) => {
52
+ const entriesClone = additionalEntries . slice ( 0 ) ;
53
+ [ ] . concat ( originalEntry ) . forEach ( ( newEntry ) => {
50
54
if ( ! entriesClone . includes ( newEntry ) ) {
51
55
entriesClone . push ( newEntry ) ;
52
56
}
@@ -56,7 +60,17 @@ function addEntries(config, options, server) {
56
60
57
61
// eslint-disable-next-line no-shadow
58
62
[ ] . concat ( config ) . forEach ( ( config ) => {
59
- config . entry = prependEntry ( config . entry || './src' ) ;
63
+ const webTarget =
64
+ config . target === 'web' ||
65
+ config . target === 'webworker' ||
66
+ config . target == null ;
67
+ const additionalEntries = webTarget ? [ clientEntry ] : [ ] ;
68
+
69
+ if ( hotEntry ) {
70
+ additionalEntries . push ( hotEntry ) ;
71
+ }
72
+
73
+ config . entry = prependEntry ( config . entry || './src' , additionalEntries ) ;
60
74
61
75
if ( options . hot || options . hotOnly ) {
62
76
config . plugins = config . plugins || [ ] ;
0 commit comments