Skip to content
This repository was archived by the owner on Nov 23, 2021. It is now read-only.

Commit 38d5f21

Browse files
committed
Use typescript plugin for build.
Makes for a slightly better bundle size.
1 parent 42fc371 commit 38d5f21

File tree

6 files changed

+187
-19
lines changed

6 files changed

+187
-19
lines changed

.babelrc renamed to babel.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
{
2-
"presets": [
1+
module.exports = {
2+
presets: [
33
[
44
"@babel/env",
55
{
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"@babel/react",
16-
"@babel/preset-typescript",
16+
"@babel/typescript"
1717
],
1818
"plugins": [
1919
"@babel/plugin-proposal-class-properties",

package-lock.json

Lines changed: 170 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@types/enzyme": "^3.9.1",
4343
"@types/jest": "^24.0.11",
4444
"@types/react": "^16.8.12",
45+
"@wessberg/rollup-plugin-ts": "^1.1.45",
4546
"babel-jest": "^24.7.1",
4647
"enzyme": "^3.9.0",
4748
"enzyme-adapter-react-16": "^1.11.2",
@@ -62,4 +63,4 @@
6263
"enzyme-to-json/serializer"
6364
]
6465
}
65-
}
66+
}

rollup.config.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
const babel = require("rollup-plugin-babel");
2-
const commonjs = require("rollup-plugin-commonjs");
31
const nodeResolve = require("rollup-plugin-node-resolve");
42
const { uglify } = require("rollup-plugin-uglify");
3+
const ts = require("@wessberg/rollup-plugin-ts");
54

65
const externalModules = ["react", "gud", "tiny-warning", "prop-types"];
76
const extensions = [".ts", ".tsx"];
@@ -13,8 +12,9 @@ const cjs = [
1312
external: externalModules,
1413
plugins: [
1514
nodeResolve({ extensions }),
16-
babel({ exclude: /node_modules/, extensions }),
17-
commonjs({ extensions }),
15+
ts({
16+
transpiler: "babel",
17+
}),
1818
]
1919
},
2020
{
@@ -23,7 +23,9 @@ const cjs = [
2323
external: externalModules,
2424
plugins: [
2525
nodeResolve({ extensions }),
26-
babel({ exclude: /node_modules/, extensions }),
26+
ts({
27+
transpiler: "babel",
28+
}),
2729
uglify(),
2830
]
2931
}
@@ -36,9 +38,8 @@ const esm = [
3638
external: externalModules,
3739
plugins: [
3840
nodeResolve({ extensions }),
39-
babel({
40-
exclude: /node_modules/,
41-
extensions,
41+
ts({
42+
transpiler: "babel",
4243
}),
4344
]
4445
}

src/implementation.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type Context<T> = {
2929

3030
export type ProviderProps<T> = {
3131
value: T;
32-
children: React.ReactNode;
32+
children?: React.ReactNode;
3333
observedBits: any,
3434
};
3535

@@ -66,7 +66,7 @@ function onlyChild(children: any): any {
6666
return Array.isArray(children) ? children[0] : children;
6767
}
6868

69-
function createReactContext<T>(defaultValue: T, calculateChangedBits?: (a: T, b: T) => number): Context<T> {
69+
export default function createReactContext<T>(defaultValue: T, calculateChangedBits?: (a: T, b: T) => number): Context<T> {
7070
const contextProp = '__create-react-context-' + gud() + '__';
7171

7272
class Provider extends Component<ProviderProps<T>> {
@@ -179,4 +179,3 @@ function createReactContext<T>(defaultValue: T, calculateChangedBits?: (a: T, b:
179179
};
180180
}
181181

182-
export default createReactContext;

tsconfig.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
},
99
"moduleResolution": "node",
1010
"jsx": "react",
11-
"emitDeclarationOnly": true,
1211
"module": "es2015",
1312
"removeComments": true,
1413
"lib": [
@@ -24,8 +23,7 @@
2423
"noImplicitAny": true,
2524
"noImplicitReturns": true,
2625
"resolveJsonModule": true,
27-
"declaration": true,
28-
"declarationDir": "dist/types",
26+
"declaration": false,
2927
},
3028
"include": [
3129
"src"

0 commit comments

Comments
 (0)