In WebpackDevMiddleware, when copying files, create any needed subdirectories. Fixes #408.

This commit is contained in:
SteveSandersonMS
2016-10-31 10:49:31 +00:00
parent 54f222e88f
commit da51cd588b
2 changed files with 8 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "aspnet-webpack", "name": "aspnet-webpack",
"version": "1.0.21", "version": "1.0.23",
"description": "Helpers for using Webpack in ASP.NET Core projects. Works in conjunction with the Microsoft.AspNetCore.SpaServices NuGet package.", "description": "Helpers for using Webpack in ASP.NET Core projects. Works in conjunction with the Microsoft.AspNetCore.SpaServices NuGet package.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@@ -93,7 +93,6 @@ function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configurati
// Attach Webpack dev middleware and optional 'hot' middleware // Attach Webpack dev middleware and optional 'hot' middleware
const compiler = webpack(webpackConfig); const compiler = webpack(webpackConfig);
const originalFileSystem = compiler.outputFileSystem;
app.use(require('webpack-dev-middleware')(compiler, { app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true, noInfo: true,
publicPath: webpackConfig.output.publicPath publicPath: webpackConfig.output.publicPath
@@ -108,7 +107,7 @@ function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configurati
// file on disk wouldn't match the file served to the browser, and the source map line numbers wouldn't // file on disk wouldn't match the file served to the browser, and the source map line numbers wouldn't
// match up. Breakpoints would either not be hit, or would hit the wrong lines. // match up. Breakpoints would either not be hit, or would hit the wrong lines.
(compiler as any).plugin('done', stats => { (compiler as any).plugin('done', stats => {
copyRecursiveSync(compiler.outputFileSystem, originalFileSystem, '/', [/\.hot-update\.(js|json)$/]); copyRecursiveToRealFsSync(compiler.outputFileSystem, '/', [/\.hot-update\.(js|json)$/]);
}); });
if (enableHotModuleReplacement) { if (enableHotModuleReplacement) {
@@ -122,7 +121,7 @@ function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configurati
} }
} }
function copyRecursiveSync(from: typeof fs, to: typeof fs, rootDir: string, exclude: RegExp[]) { function copyRecursiveToRealFsSync(from: typeof fs, rootDir: string, exclude: RegExp[]) {
from.readdirSync(rootDir).forEach(filename => { from.readdirSync(rootDir).forEach(filename => {
const fullPath = pathJoinSafe(rootDir, filename); const fullPath = pathJoinSafe(rootDir, filename);
const shouldExclude = exclude.filter(re => re.test(fullPath)).length > 0; const shouldExclude = exclude.filter(re => re.test(fullPath)).length > 0;
@@ -130,9 +129,12 @@ function copyRecursiveSync(from: typeof fs, to: typeof fs, rootDir: string, excl
const fileStat = from.statSync(fullPath); const fileStat = from.statSync(fullPath);
if (fileStat.isFile()) { if (fileStat.isFile()) {
const fileBuf = from.readFileSync(fullPath); const fileBuf = from.readFileSync(fullPath);
to.writeFile(fullPath, fileBuf); fs.writeFileSync(fullPath, fileBuf);
} else if (fileStat.isDirectory()) { } else if (fileStat.isDirectory()) {
copyRecursiveSync(from, to, fullPath, exclude); if (!fs.existsSync(fullPath)) {
fs.mkdirSync(fullPath);
}
copyRecursiveToRealFsSync(from, fullPath, exclude);
} }
} }
}); });