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

Commit

Permalink
aspnet-webpack module now preserves 'path' and 'publicPath' config se…
Browse files Browse the repository at this point in the history
…ttings when invoking Webpack compiler. Fixes #176.
  • Loading branch information
SteveSandersonMS committed Jul 18, 2016
1 parent 58bf117 commit 057efb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"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.",
"main": "index.js",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// that your loader plugins (e.g., require('./mystyles.less')) work in exactly the same way on the server as
// on the client.
import 'es6-promise';
import * as path from 'path';
import * as webpack from 'webpack';
import { requireNewCopy } from './RequireNewCopy';

Expand Down Expand Up @@ -40,7 +41,15 @@ function loadViaWebpackNoCache<T>(webpackConfigPath: string, modulePath: string)
const webpackConfig: webpack.Configuration = requireNewCopy(webpackConfigPath);
webpackConfig.entry = modulePath;
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
// (partly because it's faster, but also because otherwise there'd be different instances of modules
Expand Down Expand Up @@ -85,7 +94,7 @@ function loadViaWebpackNoCache<T>(webpackConfigPath: string, modulePath: string)
+ 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);
resolve(moduleInstance);
} catch(ex) {
Expand Down

0 comments on commit 057efb4

Please sign in to comment.