@@ -9,10 +9,9 @@ import * as webpack from 'webpack';
99import { 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' ;
1312import { requirefromstring } from './typings/require-from-string' ;
1413import { memoryfs } from './typings/memory-fs' ;
15- const ExternalsPlugin = require ( 'webpack-externals-plugin' ) as typeof webpackexternals . ExternalsPlugin ;
14+ const nodeExternals = require ( 'webpack-node-externals' ) ;
1615const requireFromString = require ( 'require-from-string' ) as typeof requirefromstring . requireFromString ;
1716const MemoryFS = require ( 'memory-fs' ) as typeof memoryfs . 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 ( 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 ( ) ) ;
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 => {
0 commit comments