From 98b861b6417399ea37aeb34c2c0e83e28fa2e9e8 Mon Sep 17 00:00:00 2001 From: Rogerio Chaves Date: Sat, 24 Sep 2016 23:17:29 -0300 Subject: [PATCH] Change warning to a hard error --- ....js => BlockUnsupportedWebpackLoaderSyntax.js} | 15 +++++++-------- packages/react-dev-utils/README.md | 8 ++++---- .../react-scripts/config/webpack.config.dev.js | 8 ++++---- 3 files changed, 15 insertions(+), 16 deletions(-) rename packages/react-dev-utils/{WarnAboutLoaderDisablingPlugin.js => BlockUnsupportedWebpackLoaderSyntax.js} (59%) diff --git a/packages/react-dev-utils/WarnAboutLoaderDisablingPlugin.js b/packages/react-dev-utils/BlockUnsupportedWebpackLoaderSyntax.js similarity index 59% rename from packages/react-dev-utils/WarnAboutLoaderDisablingPlugin.js rename to packages/react-dev-utils/BlockUnsupportedWebpackLoaderSyntax.js index e847300e5f..cd831e18a1 100644 --- a/packages/react-dev-utils/WarnAboutLoaderDisablingPlugin.js +++ b/packages/react-dev-utils/BlockUnsupportedWebpackLoaderSyntax.js @@ -7,26 +7,25 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -// This Webpack plugin warns the user when using special webpack syntax +// This Webpack plugin forbids usage of special webpack syntax // to disable loaders (https://webpack.github.io/docs/loaders.html#loader-order) // This makes it very coupled to webpack and might break in the future. // See https://github.com/facebookincubator/create-react-app/issues/733. 'use strict'; -var chalk = require('chalk'); - -class WarnAboutLoaderDisablingPlugin { +class BlockUnsupportedWebpackLoaderSyntax { apply(compiler) { compiler.plugin('normal-module-factory', (normalModuleFactory) => { normalModuleFactory.plugin('before-resolve', (data, callback) => { + let error = null; if (data.request.match(/^-?!!?/)) { - chalk.yellow(`Warning: You are requesting '${data.request}'. Special Webpack Loaders syntax is not officially supported and makes you code very coupled to Webpack, which might break in the future, we recommend that you remove it. See `https://github.com/facebookincubator/create-react-app/issues/733`); + error = `You are requesting '${data.request}'. Special Webpack Loaders syntax is not officially supported and makes you code very coupled to Webpack, which might break in the future, we recommend that you remove it. See https://github.com/facebookincubator/create-react-app/issues/733`; } - callback(null, data); - }) + callback(error, data); + }); }); } } -module.exports = WarnAboutLoaderDisablingPlugin; +module.exports = BlockUnsupportedWebpackLoaderSyntax; diff --git a/packages/react-dev-utils/README.md b/packages/react-dev-utils/README.md index 5d11b76a5a..4663dabdf0 100644 --- a/packages/react-dev-utils/README.md +++ b/packages/react-dev-utils/README.md @@ -81,7 +81,7 @@ module.exports = { } ``` -#### `new WarnAboutDisablingPlugin()` +#### `new BlockUnsupportedWebpackLoaderSyntax()` This Webpack plugin warns the user when using special webpack syntax for disabling loaders (like `!!file!./stuff`). This makes it very coupled @@ -90,17 +90,17 @@ See [#733](https://github.com/facebookincubator/create-react-app/issues/733) for ```js var path = require('path'); -var WarnAboutLoaderDisablingPlugin = require('react-dev-utils/WarnAboutLoaderDisablingPlugin); +var BlockUnsupportedWebpackLoaderSyntax = require('react-dev-utils/BlockUnsupportedWebpackLoaderSyntax'); // Webpack config module.exports = { // ... plugins: [ // ... - // This warns about using Webpack Special Loader syntax, which makes it + // This forbids usage of Webpack Special Loader syntax, which makes it // very coupled to Webpack and might break in the future. // See https://github.com/facebookincubator/create-react-app/issues/733 - new WarnAboutLoaderDisablingPlugin() + new BlockUnsupportedWebpackLoaderSyntax() ], // ... } diff --git a/packages/react-scripts/config/webpack.config.dev.js b/packages/react-scripts/config/webpack.config.dev.js index a8fc0a3a05..c79fc6b56a 100644 --- a/packages/react-scripts/config/webpack.config.dev.js +++ b/packages/react-scripts/config/webpack.config.dev.js @@ -17,7 +17,7 @@ var HtmlWebpackPlugin = require('html-webpack-plugin'); var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin'); var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); var WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin'); -var WarnAboutLoaderDisablingPlugin = require('react-dev-utils/WarnAboutLoaderDisablingPlugin'); +var BlockUnsupportedWebpackLoaderSyntax = require('react-dev-utils/BlockUnsupportedWebpackLoaderSyntax'); var getClientEnvironment = require('./env'); var paths = require('./paths'); @@ -217,11 +217,11 @@ module.exports = { // to restart the development server for Webpack to discover it. This plugin // makes the discovery automatic so you don't have to restart. // See https://github.com/facebookincubator/create-react-app/issues/186 - new WatchMissingNodeModulesPlugin(paths.appNodeModules) - // This warns about using Webpack Special Loader syntax, which makes it + new WatchMissingNodeModulesPlugin(paths.appNodeModules), + // This forbids usage of Webpack Special Loader syntax, which makes it // very coupled to Webpack and might break in the future. // See https://github.com/facebookincubator/create-react-app/issues/733 - new WarnAboutLoaderDisablingPlugin() + new BlockUnsupportedWebpackLoaderSyntax() ], // Some libraries import Node modules but don't use them in the browser. // Tell Webpack to provide empty mocks for them so importing them works.