@@ -93,7 +93,6 @@ function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configurati
9393
9494 // Attach Webpack dev middleware and optional 'hot' middleware
9595 const compiler = webpack ( webpackConfig ) ;
96- const originalFileSystem = compiler . outputFileSystem ;
9796 app . use ( require ( 'webpack-dev-middleware' ) ( compiler , {
9897 noInfo : true ,
9998 publicPath : webpackConfig . output . publicPath
@@ -108,7 +107,7 @@ function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configurati
108107 // file on disk wouldn't match the file served to the browser, and the source map line numbers wouldn't
109108 // match up. Breakpoints would either not be hit, or would hit the wrong lines.
110109 ( compiler as any ) . plugin ( 'done' , stats => {
111- copyRecursiveSync ( compiler . outputFileSystem , originalFileSystem , '/' , [ / \. h o t - u p d a t e \. ( j s | j s o n ) $ / ] ) ;
110+ copyRecursiveToRealFsSync ( compiler . outputFileSystem , '/' , [ / \. h o t - u p d a t e \. ( j s | j s o n ) $ / ] ) ;
112111 } ) ;
113112
114113 if ( enableHotModuleReplacement ) {
@@ -122,17 +121,20 @@ function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configurati
122121 }
123122}
124123
125- function copyRecursiveSync ( from : typeof fs , to : typeof fs , rootDir : string , exclude : RegExp [ ] ) {
124+ function copyRecursiveToRealFsSync ( from : typeof fs , rootDir : string , exclude : RegExp [ ] ) {
126125 from . readdirSync ( rootDir ) . forEach ( filename => {
127126 const fullPath = pathJoinSafe ( rootDir , filename ) ;
128127 const shouldExclude = exclude . filter ( re => re . test ( fullPath ) ) . length > 0 ;
129128 if ( ! shouldExclude ) {
130129 const fileStat = from . statSync ( fullPath ) ;
131130 if ( fileStat . isFile ( ) ) {
132131 const fileBuf = from . readFileSync ( fullPath ) ;
133- to . writeFile ( fullPath , fileBuf ) ;
132+ fs . writeFileSync ( fullPath , fileBuf ) ;
134133 } else if ( fileStat . isDirectory ( ) ) {
135- copyRecursiveSync ( from , to , fullPath , exclude ) ;
134+ if ( ! fs . existsSync ( fullPath ) ) {
135+ fs . mkdirSync ( fullPath ) ;
136+ }
137+ copyRecursiveToRealFsSync ( from , fullPath , exclude ) ;
136138 }
137139 }
138140 } ) ;
0 commit comments