Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit 057efb4

Browse files
aspnet-webpack module now preserves 'path' and 'publicPath' config settings when invoking Webpack compiler. Fixes #176.
1 parent 58bf117 commit 057efb4

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aspnet-webpack",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
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/LoadViaWebpack.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// that your loader plugins (e.g., require('./mystyles.less')) work in exactly the same way on the server as
55
// on the client.
66
import 'es6-promise';
7+
import * as path from 'path';
78
import * as webpack from 'webpack';
89
import { requireNewCopy } from './RequireNewCopy';
910

@@ -40,7 +41,15 @@ function loadViaWebpackNoCache<T>(webpackConfigPath: string, modulePath: string)
4041
const webpackConfig: webpack.Configuration = requireNewCopy(webpackConfigPath);
4142
webpackConfig.entry = modulePath;
4243
webpackConfig.target = 'node';
43-
webpackConfig.output = { path: '/', filename: 'webpack-output.js', libraryTarget: 'commonjs' };
44+
45+
// Make sure we preserve the 'path' and 'publicPath' config values if specified, as these
46+
// can affect the build output (e.g., when using 'file' loader, the publicPath value gets
47+
// set as a prefix on output paths).
48+
webpackConfig.output = webpackConfig.output || {};
49+
webpackConfig.output.path = webpackConfig.output.path || '/';
50+
webpackConfig.output.filename = 'webpack-output.js';
51+
webpackConfig.output.libraryTarget = 'commonjs';
52+
const outputVirtualPath = path.join(webpackConfig.output.path, webpackConfig.output.filename);
4453

4554
// In Node, we want anything under /node_modules/ to be loaded natively and not bundled into the output
4655
// (partly because it's faster, but also because otherwise there'd be different instances of modules
@@ -85,7 +94,7 @@ function loadViaWebpackNoCache<T>(webpackConfigPath: string, modulePath: string)
8594
+ stats.toString({ chunks: false }));
8695
}
8796

88-
const fileContent = compiler.outputFileSystem.readFileSync('/webpack-output.js', 'utf8');
97+
const fileContent = compiler.outputFileSystem.readFileSync(outputVirtualPath, 'utf8');
8998
const moduleInstance = requireFromString<T>(fileContent);
9099
resolve(moduleInstance);
91100
} catch(ex) {

0 commit comments

Comments
 (0)