Skip to content

Commit 3d967bf

Browse files
authored
feat: add support for tree shaking (#994)
1 parent 3b18110 commit 3d967bf

File tree

7 files changed

+1028
-76
lines changed

7 files changed

+1028
-76
lines changed

.babelrc

Lines changed: 0 additions & 46 deletions
This file was deleted.

.babelrc.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const { NODE_ENV, BABEL_ENV } = process.env
2+
const cjs = NODE_ENV === 'test' || BABEL_ENV === 'commonjs'
3+
const loose = true
4+
5+
module.exports = {
6+
presets: [
7+
[
8+
'@babel/env',
9+
{
10+
loose,
11+
modules: false,
12+
exclude: ['@babel/plugin-transform-regenerator'],
13+
},
14+
],
15+
'@babel/preset-typescript',
16+
'@babel/react',
17+
],
18+
plugins: [
19+
[
20+
'const-enum',
21+
{
22+
transform: 'constObject',
23+
},
24+
],
25+
'babel-plugin-transform-async-to-promises',
26+
cjs && ['@babel/transform-modules-commonjs', { loose }],
27+
[
28+
'@babel/transform-runtime',
29+
{
30+
useESModules: !cjs,
31+
version: require('./package.json').dependencies[
32+
'@babel/runtime'
33+
].replace(/^[^0-9]*/, ''),
34+
},
35+
],
36+
].filter(Boolean),
37+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ node_modules
77
# builds
88
build
99
dist
10+
lib
11+
es
1012
artifacts
1113
.rpt2_cache
1214
coverage

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
collectCoverage: true,
33
coverageReporters: ['json', 'lcov', 'text', 'clover', 'text-summary'],
4+
testMatch: ['<rootDir>/src/**/*.test.tsx'],
45
testPathIgnorePatterns: ['<rootDir>/types/'],
56
moduleNameMapper: {
67
'react-query': '<rootDir>/src/react/index.ts',

package.json

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
"type": "github",
1111
"url": "https://github.com/sponsors/tannerlinsley"
1212
},
13-
"main": "index.js",
13+
"main": "lib/index.js",
14+
"unpkg": "dist/react-query.development.js",
1415
"types": "types/index.d.ts",
15-
"module": "dist/react-query.mjs",
16+
"module": "es/index.js",
1617
"sideEffects": false,
1718
"scripts": {
1819
"test": "is-ci \"test:ci\" \"test:dev\"",
@@ -21,8 +22,11 @@
2122
"test:coverage": "yarn test:ci; open coverage/lcov-report/index.html",
2223
"test:types": "tsc",
2324
"test:eslint": "eslint --ext .ts,.tsx ./src",
24-
"build": "NODE_ENV=production rollup -c && rollup-plugin-visualizer stats-react.json stats-hydration.json",
25-
"build:types": "tsc --project ./tsconfig.types.json && replace 'import type' 'import' ./types -r && replace 'export type' 'export' ./types -r",
25+
"build": "yarn build:commonjs && yarn build:es && yarn build:umd",
26+
"build:commonjs": "rm -rf ./lib && BABEL_ENV=commonjs babel --extensions .ts,.tsx --ignore ./src/**/*.test.tsx ./src --out-dir lib",
27+
"build:es": "rm -rf ./es && babel --extensions .ts,.tsx --ignore ./src/**/*.test.tsx ./src --out-dir es",
28+
"build:umd": "rm -rf ./dist && NODE_ENV=production rollup -c && rollup-plugin-visualizer stats-react.json stats-hydration.json",
29+
"build:types": "rm -rf ./types && tsc --project ./tsconfig.types.json && replace 'import type' 'import' ./types -r && replace 'export type' 'export' ./types -r",
2630
"now-build": "yarn && cd www && yarn && yarn build",
2731
"start": "rollup -c -w",
2832
"format": "prettier {.,src,src/**,example/src,example/src/**,types}/*.{md,js,jsx,tsx,json} --write",
@@ -40,19 +44,33 @@
4044
},
4145
"files": [
4246
"dist",
47+
"lib",
48+
"es",
4349
"types",
4450
"scripts",
4551
"hydration.js",
4652
"hydration.d.ts"
4753
],
48-
"dependencies": {},
54+
"dependencies": {
55+
"@babel/runtime": "^7.5.5"
56+
},
4957
"peerDependencies": {
5058
"react": "^16.8.0"
5159
},
60+
"peerDependenciesMeta": {
61+
"react-dom": {
62+
"optional": true
63+
},
64+
"react-native": {
65+
"optional": true
66+
}
67+
},
5268
"devDependencies": {
53-
"@babel/core": "^7.10.2",
54-
"@babel/preset-env": "^7.10.2",
55-
"@babel/preset-react": "^7.10.1",
69+
"@babel/cli": "^7.11.6",
70+
"@babel/core": "^7.11.6",
71+
"@babel/plugin-transform-runtime": "^7.11.5",
72+
"@babel/preset-env": "^7.11.5",
73+
"@babel/preset-react": "^7.10.4",
5674
"@babel/preset-typescript": "^7.10.4",
5775
"@rollup/plugin-replace": "^2.3.3",
5876
"@svgr/rollup": "^5.4.0",

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const inputSrc = 'src/index.ts'
2222
const hydrationSrc = 'src/hydration/index.ts'
2323

2424
const extensions = ['.js', '.jsx', '.es6', '.es', '.mjs', '.ts', '.tsx']
25-
const babelConfig = { extensions }
25+
const babelConfig = { extensions, runtimeHelpers: true }
2626
const resolveConfig = { extensions }
2727

2828
export default [

0 commit comments

Comments
 (0)