Skip to content

Commit da51cd5

Browse files
In WebpackDevMiddleware, when copying files, create any needed subdirectories. Fixes aspnet#408.
1 parent 54f222e commit da51cd5

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aspnet-webpack",
3-
"version": "1.0.21",
3+
"version": "1.0.23",
44
"description": "Helpers for using Webpack in ASP.NET Core projects. Works in conjunction with the Microsoft.AspNetCore.SpaServices NuGet package.",
55
"main": "index.js",
66
"scripts": {

src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/WebpackDevMiddleware.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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, '/', [/\.hot-update\.(js|json)$/]);
110+
copyRecursiveToRealFsSync(compiler.outputFileSystem, '/', [/\.hot-update\.(js|json)$/]);
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

Comments
 (0)