11import errorOverlayMiddleware from 'react-dev-utils/errorOverlayMiddleware'
22
3+ const chunkPathBasic = require . resolve ( './entry-basic' )
4+ const chunkPathDevServer = require . resolve ( './entry-devserver' )
5+
36class ErrorOverlayPlugin {
47 apply ( compiler ) {
58 const className = this . constructor . name
69
710 if ( compiler . options . mode !== 'development' ) return
811
12+ const devServerEnabled = ! ! compiler . options . devServer
13+
914 compiler . hooks . entryOption . tap ( className , ( context , entry ) => {
10- const chunkPath = require . resolve ( './entry' )
11- adjustEntry ( entry , chunkPath )
15+ adjustEntry ( entry , devServerEnabled )
1216 } )
1317
1418 compiler . hooks . afterResolvers . tap ( className , ( { options } ) => {
15- if ( options . devServer ) {
19+ if ( devServerEnabled ) {
1620 const originalBefore = options . devServer . before
1721 options . devServer . before = ( app , server ) => {
1822 if ( originalBefore ) {
@@ -25,7 +29,7 @@ class ErrorOverlayPlugin {
2529 }
2630}
2731
28- function adjustEntry ( entry , chunkPath ) {
32+ function adjustEntry ( entry , enableDevServer ) {
2933 if ( typeof entry === 'string' ) {
3034 throw new Error (
3135 `We currently do not inject our entry code into single-file anonymous entries.
@@ -34,12 +38,18 @@ Please use a multi-main (array) or object-form \`entry\` setting for now.`,
3438 }
3539
3640 if ( Array . isArray ( entry ) ) {
37- if ( ! entry . includes ( chunkPath ) ) {
38- entry . unshift ( chunkPath )
41+ if ( enableDevServer ) {
42+ if ( ! entry . includes ( chunkPathDevServer ) ) {
43+ entry . unshift ( chunkPathDevServer )
44+ }
45+ }
46+
47+ if ( ! entry . includes ( chunkPathBasic ) ) {
48+ entry . unshift ( chunkPathBasic )
3949 }
4050 } else {
4151 Object . keys ( entry ) . forEach ( entryName => {
42- entry [ entryName ] = adjustEntry ( entry [ entryName ] , chunkPath )
52+ entry [ entryName ] = adjustEntry ( entry [ entryName ] , enableDevServer )
4353 } )
4454 }
4555
0 commit comments