Handle Webpack 2.1.0 beta 23 renaming 'loaders' to 'rules'. Fixes #460.

This commit is contained in:
SteveSandersonMS
2016-11-25 10:15:38 +00:00
parent 8401bbf33a
commit 69a0a29057
2 changed files with 6 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "aspnet-webpack-react", "name": "aspnet-webpack-react",
"version": "1.0.2", "version": "1.0.3",
"description": "Helpers for using Webpack with React in ASP.NET Core projects. Works in conjunction with the Microsoft.AspNetCore.SpaServices NuGet package.", "description": "Helpers for using Webpack with React in ASP.NET Core projects. Works in conjunction with the Microsoft.AspNetCore.SpaServices NuGet package.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@@ -1,7 +1,11 @@
import * as webpack from 'webpack'; import * as webpack from 'webpack';
export function addReactHotModuleReplacementBabelTransform(webpackConfig: webpack.Configuration) { export function addReactHotModuleReplacementBabelTransform(webpackConfig: webpack.Configuration) {
webpackConfig.module.loaders.forEach(loaderConfig => { const moduleRules: webpack.Loader[] =
(webpackConfig.module as any).rules // Webpack < 2.1.0 beta 23
|| webpackConfig.module.loaders; // Webpack >= 2.1.0 beta 23
moduleRules.forEach(loaderConfig => {
if (loaderConfig.loader && loaderConfig.loader.match(/\bbabel-loader\b/)) { if (loaderConfig.loader && loaderConfig.loader.match(/\bbabel-loader\b/)) {
// Ensure the babel-loader options includes a 'query' // Ensure the babel-loader options includes a 'query'
const query = loaderConfig.query = loaderConfig.query || {}; const query = loaderConfig.query = loaderConfig.query || {};