aspnet-webpack module now preserves 'path' and 'publicPath' config settings when invoking Webpack compiler. Fixes #176.

This commit is contained in:
SteveSandersonMS
2016-07-18 13:55:26 +01:00
parent 58bf117442
commit 057efb43c8
2 changed files with 12 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "aspnet-webpack", "name": "aspnet-webpack",
"version": "1.0.5", "version": "1.0.6",
"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

@@ -4,6 +4,7 @@
// that your loader plugins (e.g., require('./mystyles.less')) work in exactly the same way on the server as // that your loader plugins (e.g., require('./mystyles.less')) work in exactly the same way on the server as
// on the client. // on the client.
import 'es6-promise'; import 'es6-promise';
import * as path from 'path';
import * as webpack from 'webpack'; import * as webpack from 'webpack';
import { requireNewCopy } from './RequireNewCopy'; import { requireNewCopy } from './RequireNewCopy';
@@ -40,7 +41,15 @@ function loadViaWebpackNoCache<T>(webpackConfigPath: string, modulePath: string)
const webpackConfig: webpack.Configuration = requireNewCopy(webpackConfigPath); const webpackConfig: webpack.Configuration = requireNewCopy(webpackConfigPath);
webpackConfig.entry = modulePath; webpackConfig.entry = modulePath;
webpackConfig.target = 'node'; webpackConfig.target = 'node';
webpackConfig.output = { path: '/', filename: 'webpack-output.js', libraryTarget: 'commonjs' };
// Make sure we preserve the 'path' and 'publicPath' config values if specified, as these
// can affect the build output (e.g., when using 'file' loader, the publicPath value gets
// set as a prefix on output paths).
webpackConfig.output = webpackConfig.output || {};
webpackConfig.output.path = webpackConfig.output.path || '/';
webpackConfig.output.filename = 'webpack-output.js';
webpackConfig.output.libraryTarget = 'commonjs';
const outputVirtualPath = path.join(webpackConfig.output.path, webpackConfig.output.filename);
// In Node, we want anything under /node_modules/ to be loaded natively and not bundled into the output // In Node, we want anything under /node_modules/ to be loaded natively and not bundled into the output
// (partly because it's faster, but also because otherwise there'd be different instances of modules // (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)
+ stats.toString({ chunks: false })); + stats.toString({ chunks: false }));
} }
const fileContent = compiler.outputFileSystem.readFileSync('/webpack-output.js', 'utf8'); const fileContent = compiler.outputFileSystem.readFileSync(outputVirtualPath, 'utf8');
const moduleInstance = requireFromString<T>(fileContent); const moduleInstance = requireFromString<T>(fileContent);
resolve(moduleInstance); resolve(moduleInstance);
} catch(ex) { } catch(ex) {