Skip to content

Commit

Permalink
Change warning to a hard error
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeriochaves committed Sep 25, 2016
1 parent 0f27bdc commit 98b861b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
8 changes: 4 additions & 4 deletions packages/react-dev-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
],
// ...
}
Expand Down
8 changes: 4 additions & 4 deletions packages/react-scripts/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 98b861b

Please sign in to comment.