mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 01:58:29 +00:00
In aspnet-webpack, replace ExternalsPlugin with webpack-node-externals because of #132
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "aspnet-webpack",
|
"name": "aspnet-webpack",
|
||||||
"version": "1.0.11",
|
"version": "1.0.12",
|
||||||
"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": {
|
||||||
@@ -10,12 +10,12 @@
|
|||||||
"author": "Microsoft",
|
"author": "Microsoft",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"es6-promise": "^3.1.2",
|
|
||||||
"connect": "^3.4.1",
|
"connect": "^3.4.1",
|
||||||
|
"es6-promise": "^3.1.2",
|
||||||
"memory-fs": "^0.3.0",
|
"memory-fs": "^0.3.0",
|
||||||
"require-from-string": "^1.1.0",
|
"require-from-string": "^1.1.0",
|
||||||
"webpack-dev-middleware": "^1.6.1",
|
"webpack-dev-middleware": "^1.6.1",
|
||||||
"webpack-externals-plugin": "^1.0.0"
|
"webpack-node-externals": "^1.4.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tsd": "0.6.5",
|
"tsd": "0.6.5",
|
||||||
|
|||||||
@@ -9,10 +9,9 @@ import * as webpack from 'webpack';
|
|||||||
import { requireNewCopy } from './RequireNewCopy';
|
import { requireNewCopy } from './RequireNewCopy';
|
||||||
|
|
||||||
// Strange import syntax to work around https://github.com/Microsoft/TypeScript/issues/2719
|
// Strange import syntax to work around https://github.com/Microsoft/TypeScript/issues/2719
|
||||||
import { webpackexternals } from './typings/webpack-externals-plugin';
|
|
||||||
import { requirefromstring } from './typings/require-from-string';
|
import { requirefromstring } from './typings/require-from-string';
|
||||||
import { memoryfs } from './typings/memory-fs';
|
import { memoryfs } from './typings/memory-fs';
|
||||||
const ExternalsPlugin = require('webpack-externals-plugin') as typeof webpackexternals.ExternalsPlugin;
|
const nodeExternals = require('webpack-node-externals');
|
||||||
const requireFromString = require('require-from-string') as typeof requirefromstring.requireFromString;
|
const requireFromString = require('require-from-string') as typeof requirefromstring.requireFromString;
|
||||||
const MemoryFS = require('memory-fs') as typeof memoryfs.MemoryFS;
|
const MemoryFS = require('memory-fs') as typeof memoryfs.MemoryFS;
|
||||||
|
|
||||||
@@ -59,9 +58,19 @@ function loadViaWebpackNoCache<T>(webpackConfigPath: string, modulePath: string)
|
|||||||
|
|
||||||
// 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
|
||||||
// depending on how they were loaded, which could lead to errors)
|
// depending on how they were loaded, which could lead to errors).
|
||||||
webpackConfig.plugins = webpackConfig.plugins || [];
|
// ---
|
||||||
webpackConfig.plugins.push(new ExternalsPlugin({ type: 'commonjs', include: /node_modules/ }));
|
// NOTE: We have to use webpack-node-externals rather than webpack-externals-plugin because
|
||||||
|
// webpack-externals-plugin doesn't correctly resolve relative paths, which means you can't
|
||||||
|
// use css-loader, since tries to require('./../../node_modules/css-loader/lib/css-base.js') (see #132)
|
||||||
|
// ---
|
||||||
|
// So, ensure that webpackConfig.externals is an array, and push WebpackNodeExternals into it:
|
||||||
|
let externalsArray: any[] = (webpackConfig.externals as any[]) || [];
|
||||||
|
if (!(externalsArray instanceof Array)) {
|
||||||
|
externalsArray = [externalsArray];
|
||||||
|
}
|
||||||
|
webpackConfig.externals = externalsArray;
|
||||||
|
externalsArray.push(nodeExternals());
|
||||||
|
|
||||||
// The CommonsChunkPlugin is not compatible with a CommonJS environment like Node, nor is it needed in that case
|
// The CommonsChunkPlugin is not compatible with a CommonJS environment like Node, nor is it needed in that case
|
||||||
webpackConfig.plugins = webpackConfig.plugins.filter(plugin => {
|
webpackConfig.plugins = webpackConfig.plugins.filter(plugin => {
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
import * as webpack from 'webpack';
|
|
||||||
|
|
||||||
export namespace webpackexternals {
|
|
||||||
export interface ExternalsPluginOptions {
|
|
||||||
type: string;
|
|
||||||
include: webpack.LoaderCondition;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ExternalsPlugin {
|
|
||||||
constructor(options: ExternalsPluginOptions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
declare module 'webpack-node-externals' {
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user