Skip to content

Commit 3cadc06

Browse files
committed
build: optimize the rollup build
- remove babel-runtime - add babel-dev-expressions - switch to tiny-invariant
1 parent f1f86a4 commit 3cadc06

File tree

6 files changed

+1320
-1292
lines changed

6 files changed

+1320
-1292
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"unpkg": "react-intersection-observer.umd.min.js",
88
"typings": "index.d.ts",
99
"author": "Daniel Schmidt",
10+
"sideEffects": false,
1011
"repository": {
1112
"type": "git",
1213
"url": "https://github.com/thebuilder/react-intersection-observer.git"
@@ -109,7 +110,6 @@
109110
]
110111
},
111112
"dependencies": {
112-
"@babel/runtime": "^7.0.0",
113113
"invariant": "^2.0.0"
114114
},
115115
"peerDependencies": {
@@ -134,14 +134,13 @@
134134
"@types/jest": "^24.0.18",
135135
"@types/react": "^16.9.1",
136136
"@types/react-dom": "^16.9.0",
137-
"@types/storybook__addon-actions": "^3.4.1",
138-
"@types/storybook__addon-knobs": "^5.0.2",
139137
"@types/storybook__react": "^4.0.0",
140138
"@typescript-eslint/eslint-plugin": "^2.0.0",
141139
"@typescript-eslint/parser": "^2.0.0",
142140
"babel-eslint": "^10.0.3",
143141
"babel-jest": "^24.5.0",
144142
"babel-loader": "^8.0.5",
143+
"babel-plugin-dev-expression": "^0.2.2",
145144
"concurrently": "^5.0.0",
146145
"coveralls": "^3.0.5",
147146
"eslint": "^6.2.1",
@@ -166,6 +165,7 @@
166165
"rollup-plugin-node-resolve": "^5.2.0",
167166
"rollup-plugin-replace": "^2.1.0",
168167
"rollup-plugin-terser": "^5.1.1",
168+
"tiny-invariant": "^1.0.6",
169169
"typescript": "^3.5.3"
170170
}
171171
}

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const getBabelOptions = ({ useESModules }) => ({
2020
extensions,
2121
include: ['src/**/*'],
2222
presets: ['@babel/preset-typescript'],
23-
plugins: [['@babel/transform-runtime', { regenerator: false, useESModules }]],
23+
plugins: [['babel-plugin-dev-expression']],
2424
})
2525

2626
export default [

src/InView.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react'
2-
import invariant from 'invariant'
2+
import invariant from 'tiny-invariant'
33
import { observe, unobserve } from './intersection'
44
import { IntersectionObserverProps, PlainChildrenProps } from './index'
55

@@ -39,13 +39,10 @@ export class InView extends React.Component<
3939
}
4040

4141
componentDidMount() {
42-
/* istanbul ignore else */
43-
if (process.env.NODE_ENV !== 'production') {
44-
invariant(
45-
this.node,
46-
`react-intersection-observer: No DOM node found. Make sure you forward "ref" to the root DOM element you want to observe.`,
47-
)
48-
}
42+
invariant(
43+
this.node,
44+
`react-intersection-observer: No DOM node found. Make sure you forward "ref" to the root DOM element you want to observe.`,
45+
)
4946
}
5047

5148
componentDidUpdate(prevProps: IntersectionObserverProps, prevState: State) {

src/__tests__/Observer.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import React from 'react'
33
import { fireEvent, render } from '@testing-library/react'
44
import { observe, unobserve } from '../intersection'
55
import Observer from '../'
6-
import invariant from 'invariant'
6+
import invariant from 'tiny-invariant'
77

88
jest.mock('../intersection')
9-
jest.mock('invariant')
9+
jest.mock('tiny-invariant')
1010

1111
const plainChild = ({ ref }) => <div ref={ref} />
1212
afterEach(() => {

src/intersection.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import invariant from 'invariant'
1+
import invariant from 'tiny-invariant'
22
import { ObserverInstance, ObserverInstanceCallback } from './index'
33

44
const INSTANCE_MAP: Map<Element, ObserverInstance> = new Map()
@@ -41,7 +41,6 @@ export function observe(
4141
invariant(
4242
!INSTANCE_MAP.has(element),
4343
"react-intersection-observer: Trying to observe %s, but it's already being observed by another instance.\nMake sure the `ref` is only used by a single <Observer /> instance.\n\n%s",
44-
element,
4544
)
4645
/* istanbul ignore if */
4746
if (!element) return

0 commit comments

Comments
 (0)