Skip to content

Commit f53bfe7

Browse files
committed
make env configurable
1 parent 42a9d60 commit f53bfe7

File tree

5 files changed

+7
-4
lines changed

5 files changed

+7
-4
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ The asynchronous component factory. Config goes in, an asynchronous component co
103103
- `ErrorComponent` (_Component_, Optional, default: `null`) : A Component that will be displayed if any error occurred whilst trying to resolve your component. All props will be passed to it as well as an `error` prop containing the `Error`.
104104
- `name` (_String_, Optional, default: `'AsyncComponent'`) : Use this if you would like to name the created async Component, which helps when firing up the React Dev Tools for example.
105105
- `autoResolveES2015Default` (_Boolean_, Optional, default: `true`) : Especially useful if you are resolving ES2015 modules. The resolved module will be checked to see if it has a `.default` and if so then the value attached to `.default` will be used. So easy to forget to do that. 😀
106+
- `env` (_String_, Optional) : Provide either `'node'` or `'browser'` so you can write your own environment detection. Especially useful when using PhantomJS or ElectronJS to prerender the React App.
106107
- `serverMode` (_Boolean_, Optional, default: `'resolve'`) : Only applies for server side rendering applications. Please see the documentation on server side rendering. The following values are allowed.
107108
- __`'resolve'`__ - Your asynchronous component will be resolved and rendered on the server. It's children will
108109
be checked to see if there are any nested asynchronous component instances, which will then be processed based on the `serverMode` value that was associated with them.

commonjs/asyncComponent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function asyncComponent(config) {
3939
throw new Error('Invalid serverMode provided to asyncComponent');
4040
}
4141

42-
var env = typeof window === 'undefined' ? 'node' : 'browser';
42+
var env = ['node', 'browser'].indexOf(config.env) > -1 ? config.env : typeof window === 'undefined' ? 'node' : 'browser';
4343

4444
var sharedState = {
4545
// A unique id we will assign to our async component which is especially

src/asyncComponent.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ function asyncComponent(config) {
1616
throw new Error('Invalid serverMode provided to asyncComponent')
1717
}
1818

19-
const env = typeof window === 'undefined' ? 'node' : 'browser'
19+
const env = ['node', 'browser'].indexOf(config.env) > -1
20+
? config.env
21+
: typeof window === 'undefined' ? 'node' : 'browser'
2022

2123
const sharedState = {
2224
// A unique id we will assign to our async component which is especially

umd/react-async-component.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ function asyncComponent(config) {
260260
throw new Error('Invalid serverMode provided to asyncComponent');
261261
}
262262

263-
var env = typeof window === 'undefined' ? 'node' : 'browser';
263+
var env = ['node', 'browser'].indexOf(config.env) > -1 ? config.env : typeof window === 'undefined' ? 'node' : 'browser';
264264

265265
var sharedState = {
266266
// A unique id we will assign to our async component which is especially

umd/react-async-component.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)