Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use @babel/runtime helpers and define module field in package.json #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<PROJECT_ROOT>/lib/.*
<PROJECT_ROOT>/es/.*
<PROJECT_ROOT>/node8/.*
<PROJECT_ROOT>/ie11/.*
.*/node_modules/@babel/.*
.*/node_modules/ajv.*
.*/node_modules/acorn.*
.*/node_modules/async.*
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ node_modules
/lib
/node8
/mjs
/ie11

coverage
.nyc_output
23 changes: 5 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,6 @@ OR
npm install react-relay-network-modern --save
```

### What if `regeneratorRuntime is not defined`?

<img width="493" alt="screen shot 2018-02-20 at 20 07 45" src="https://user-images.githubusercontent.com/1946920/36428334-da402a6e-1679-11e8-9897-7e730ab3123e.png">

I don't want to bundle regenerator-runtime with the library - it's a largish dependency and there's a good chance that the user is already including code which depends on it (eg. via `babel-polyfill`). If we bundle it they'll get a duplicate copy and that's bad.

So if you got `regeneratorRuntime is not defined` you should do the following:

```js
import 'regenerator-runtime/runtime';
import { RelayNetworkLayer } from 'react-relay-network-modern';
```

### What if Webpack errors with `Error: Cannot find module 'core-js/modules/es6.*'`?

`core-js` is not an explicit dependency as it adds [30kb for client bundles](https://bundlephobia.com/[email protected]).
Expand All @@ -54,15 +41,15 @@ If this error occurs you can do one of the following:
This library contains different builds for any purposes:

```js
// Default import for using in any browser
// last 5 versions, ie 9, defaults
// Default import for using in modern browsers
// last 5 version and not dead, defaults
import { RelayNetworkLayer } from 'react-relay-network-modern';

// For IE11
import { RelayNetworkLayer } from 'react-relay-network-modern/ie11';

// For SSR on node 8 and above (native async/await)
import { RelayNetworkLayer } from 'react-relay-network-modern/node8';

// Source code without Flowtype declarations
import { RelayNetworkLayer } from 'react-relay-network-modern/es';
```

## Middlewares
Expand Down
33 changes: 26 additions & 7 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
module.exports = {
plugins: [
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-transform-flow-strip-types',
],
plugins: ['@babel/plugin-transform-runtime'],
presets: ['@babel/preset-flow'],
env: {
lib: {
plugins: ['@babel/plugin-proposal-class-properties'],
presets: [
[
'@babel/preset-env',
{
targets: {
browsers: ['last 5 versions', 'ie 11', 'defaults'],
browsers: ['last 5 versions and not dead', 'defaults'],
},
},
],
],
},
es: {
plugins: ['@babel/plugin-proposal-class-properties'],
presets: [
[
'@babel/preset-env',
{
targets: {
browsers: ['last 5 versions and not dead', 'defaults'],
},
modules: false,
},
],
],
},
node8: {
presets: [
Expand All @@ -33,6 +40,18 @@ module.exports = {
],
],
},
ie11: {
presets: [
[
'@babel/preset-env',
{
targets: {
browsers: ['ie 11'],
},
},
],
],
},
test: {
presets: [
[
Expand Down
25 changes: 12 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
"files": [
"es",
"lib",
"node8"
"node8",
"ie11"
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
"module": "es/index.js",
"repository": {
"type": "git",
"url": "https://github.com/relay-tools/react-relay-network-modern.git"
Expand All @@ -32,25 +34,21 @@
},
"homepage": "https://github.com/relay-tools/react-relay-network-modern#readme",
"dependencies": {
"@babel/runtime": "^7.0.0",
"core-js": "^3.0.0",
"extract-files": "^9.0.0"
},
"peerDependencies": {
"relay-runtime": ">=1.4.0"
},
"devDependencies": {
"@babel/cli": "7.16.0",
"@babel/core": "7.16.0",
"@babel/plugin-proposal-class-properties": "7.16.0",
"@babel/plugin-proposal-object-rest-spread": "7.16.0",
"@babel/plugin-proposal-optional-chaining": "^7.4.4",
"@babel/plugin-transform-flow-strip-types": "7.16.0",
"@babel/polyfill": "7.12.1",
"@babel/preset-env": "7.16.0",
"@babel/preset-flow": "7.16.0",
"@babel/register": "7.16.0",
"@babel/cli": "^7.19.3",
"@babel/core": "^7.19.6",
"@babel/plugin-transform-runtime": "^7.19.6",
"@babel/preset-env": "^7.19.4",
"@babel/preset-flow": "^7.18.6",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "10.1.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^24.8.0",
"cz-conventional-changelog": "^2.1.0",
"eslint": "^5.16.0",
Expand Down Expand Up @@ -83,10 +81,11 @@
]
},
"scripts": {
"build": "npm run build-lib && npm run build-es && npm run build-node8",
"build": "npm run build-lib && npm run build-es && npm run build-node8 && npm run build-ie11",
"build-lib": "rimraf lib && BABEL_ENV=lib babel src --ignore __tests__,__mocks__ -d lib && COPY_TO_FOLDER=lib npm run build-flow && COPY_TO_FOLDER=lib npm run build-dts ",
"build-es": "rimraf es && BABEL_ENV=es babel src --ignore __tests__,__mocks__ -d es && COPY_TO_FOLDER=es npm run build-flow && COPY_TO_FOLDER=es npm run build-dts",
"build-node8": "rimraf node8 && BABEL_ENV=node8 babel src --ignore __tests__,__mocks__ -d node8 && COPY_TO_FOLDER=node8 npm run build-flow && COPY_TO_FOLDER=node8 npm run build-dts",
"build-ie11": "rimraf ie11 && BABEL_ENV=ie11 babel src --ignore __tests__,__mocks__ -d ie11 && COPY_TO_FOLDER=ie11 npm run build-flow && COPY_TO_FOLDER=ie11 npm run build-dts",
"build-flow": "echo `$1` && find ./src -name '*.js' -not -path '*/__*' | while read filepath; do cp $filepath `echo ./${COPY_TO_FOLDER:-lib}$filepath | sed 's/.\\/src\\//\\//g'`.flow; done",
"build-dts": "echo `$1` && find ./src -name '*d.ts' -not -path '*/__*' | while read filepath; do cp $filepath `echo ./${COPY_TO_FOLDER:-lib}$filepath | sed 's/.\\/src\\//\\//g'`; done",
"lint": "npm run eslint && npm run tslint && npm run tscheck",
Expand Down
Loading