From b4b80bc72e66a5838b6d6176f4c15c211bccc1c6 Mon Sep 17 00:00:00 2001 From: Martin Barksten Date: Tue, 28 Jan 2020 08:46:51 +0100 Subject: [PATCH] Document how to build for older browsers Document how to transpile your node_modules with babel to be able to target older browsers. --- docs/getting-started/installation.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/getting-started/installation.md b/docs/getting-started/installation.md index 1f87cdcb..3393eef8 100644 --- a/docs/getting-started/installation.md +++ b/docs/getting-started/installation.md @@ -14,3 +14,29 @@ yarn add react-async > This package requires `react` as a peer dependency. Please make sure to install that as well. If you want to use the > `useAsync` hook, you'll need `react@16.8.0` or later. + +## Targeting older browsers + +If you are targeting older browsers you need to transpile `react-async` with babel. + +To transpile `node_modules` with babel you need to use a `babel.config.js`, for more information see [babel's documentation](https://babeljs.io/docs/en/configuration#whats-your-use-case). + +In your `webpack.config.js` make sure that the rule for `babel-loader`: + * doesn't exclude `node_modules` from matching via the `exclude` pattern; + * excludes `core-js` as it shouldn't be transpiled; + * is passed the `configFile` option pointing to the `babel.config.js` file. + +``` +{ + test: /\.(js|jsx)$/, + exclude: /\/node_modules\/core-js\//, + use: [{ + loader: 'babel-loader', + options: { + configFile: './babel.config.js', + // This is recommended to enable when transpiling node_modules to improve build times for consecutive builds. + cacheDirectory: true, + } + }] +} +```