@@ -9,10 +9,9 @@ import * as webpack from 'webpack';
9
9
import { requireNewCopy } from './RequireNewCopy' ;
10
10
11
11
// Strange import syntax to work around https://github.com/Microsoft/TypeScript/issues/2719
12
- import { webpackexternals } from './typings/webpack-externals-plugin' ;
13
12
import { requirefromstring } from './typings/require-from-string' ;
14
13
import { memoryfs } from './typings/memory-fs' ;
15
- const ExternalsPlugin = require ( 'webpack-externals-plugin' ) as typeof webpackexternals . ExternalsPlugin ;
14
+ const nodeExternals = require ( 'webpack-node-externals' ) ;
16
15
const requireFromString = require ( 'require-from-string' ) as typeof requirefromstring . requireFromString ;
17
16
const MemoryFS = require ( 'memory-fs' ) as typeof memoryfs . MemoryFS ;
18
17
@@ -59,9 +58,19 @@ function loadViaWebpackNoCache<T>(webpackConfigPath: string, modulePath: string)
59
58
60
59
// In Node, we want anything under /node_modules/ to be loaded natively and not bundled into the output
61
60
// (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 ( new ExternalsPlugin ( { type : 'commonjs' , include : / n o d e _ m o d u l e s / } ) ) ;
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
+ let externalsArray : any [ ] = ( webpackConfig . externals as any [ ] ) || [ ] ;
69
+ if ( ! ( externalsArray instanceof Array ) ) {
70
+ externalsArray = [ externalsArray ] ;
71
+ }
72
+ webpackConfig . externals = externalsArray ;
73
+ externalsArray . push ( nodeExternals ( ) ) ;
65
74
66
75
// The CommonsChunkPlugin is not compatible with a CommonJS environment like Node, nor is it needed in that case
67
76
webpackConfig . plugins = webpackConfig . plugins . filter ( plugin => {
0 commit comments