Skip to content

Commit 80343e9

Browse files
In aspnet-webpack, replace ExternalsPlugin with webpack-node-externals because of aspnet#132
1 parent f7ef36b commit 80343e9

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aspnet-webpack",
3-
"version": "1.0.11",
3+
"version": "1.0.12",
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":{
@@ -10,12 +10,12 @@
1010
"author": "Microsoft",
1111
"license": "Apache-2.0",
1212
"dependencies":{
13-
"es6-promise": "^3.1.2",
1413
"connect": "^3.4.1",
14+
"es6-promise": "^3.1.2",
1515
"memory-fs": "^0.3.0",
1616
"require-from-string": "^1.1.0",
1717
"webpack-dev-middleware": "^1.6.1",
18-
"webpack-externals-plugin": "^1.0.0"
18+
"webpack-node-externals": "^1.4.3"
1919
},
2020
"devDependencies":{
2121
"tsd": "0.6.5",

‎src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/LoadViaWebpack.ts‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ import * as webpack from 'webpack'
99
import{requireNewCopy}from'./RequireNewCopy';
1010

1111
// Strange import syntax to work around https://github.com/Microsoft/TypeScript/issues/2719
12-
import{webpackexternals}from'./typings/webpack-externals-plugin';
1312
import{requirefromstring}from'./typings/require-from-string';
1413
import{memoryfs}from'./typings/memory-fs';
15-
constExternalsPlugin=require('webpack-externals-plugin')astypeofwebpackexternals.ExternalsPlugin;
14+
constnodeExternals=require('webpack-node-externals');
1615
constrequireFromString=require('require-from-string')astypeofrequirefromstring.requireFromString;
1716
constMemoryFS=require('memory-fs')astypeofmemoryfs.MemoryFS;
1817

@@ -59,9 +58,19 @@ function loadViaWebpackNoCache<T>(webpackConfigPath: string, modulePath: string)
5958

6059
// In Node, we want anything under /node_modules/ to be loaded natively and not bundled into the output
6160
// (partly because it's faster, but also because otherwise there'd be different instances of modules
62-
// depending on how they were loaded, which could lead to errors)
63-
webpackConfig.plugins=webpackConfig.plugins||[];
64-
webpackConfig.plugins.push(newExternalsPlugin({type: 'commonjs',include: /node_modules/}));
61+
// depending on how they were loaded, which could lead to errors).
62+
// ---
63+
// NOTE: We have to use webpack-node-externals rather than webpack-externals-plugin because
64+
// webpack-externals-plugin doesn't correctly resolve relative paths, which means you can't
65+
// use css-loader, since tries to require('./../../node_modules/css-loader/lib/css-base.js') (see #132)
66+
// ---
67+
// So, ensure that webpackConfig.externals is an array, and push WebpackNodeExternals into it:
68+
letexternalsArray: any[]=(webpackConfig.externalsasany[])||[];
69+
if(!(externalsArrayinstanceofArray)){
70+
externalsArray=[externalsArray];
71+
}
72+
webpackConfig.externals=externalsArray;
73+
externalsArray.push(nodeExternals());
6574

6675
// The CommonsChunkPlugin is not compatible with a CommonJS environment like Node, nor is it needed in that case
6776
webpackConfig.plugins=webpackConfig.plugins.filter(plugin=>{

‎src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/typings/webpack-externals-plugin.d.ts‎

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare module 'webpack-node-externals'{
2+
}

0 commit comments

Comments
(0)