Skip to content

Commit 6984694

Browse files
fix: generate tree-shakable bundles
1 parent 82b9853 commit 6984694

File tree

5 files changed

+427
-40
lines changed

5 files changed

+427
-40
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
- [Mock HTML5 Canvas in JSDOM](#mock-html5-canvas-in-jsdom)
2828
- [Mock an entire library](#mock-an-entire-library)
2929
- [Mock complex objects](#mock-complex-objects)
30+
- [Browser/Node Support](#browsernode-support)
31+
- [Performance & Size](#performance--size)
3032

3133
## About
3234

@@ -301,3 +303,11 @@ logoutHandler(req, res);
301303
// Assert that res.redirect() has been called
302304
expect(hasPathBeenVisited(res, ["redirect", ProxySymbol.APPLY])).toStrictEqual(true);
303305
```
306+
307+
## Browser/Node Support
308+
309+
Out of the box we support all browsers that support the [Proxy object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#browser_compatibility) and any current LTS version of Node. Unfortunately Proxy cannot be polyfilled for older versions so this is the best browser support we can do.
310+
311+
## Performance & Size
312+
313+
It's important to note that Proxies are far slower than most alternatives. We wouldn't recommend to use this for performance-critical code. The library is heavily tree-shakable so the average bundle size will be just a few KBs.

babel.config.js

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,49 @@
1-
module.exports = {
2-
presets: [
3-
[
1+
const packageJSON = require("./package.json");
2+
3+
const transformRuntimeVersion = packageJSON.devDependencies["@babel/plugin-transform-runtime"];
4+
5+
module.exports = (api) => {
6+
const isTest = api.env("test");
7+
const config = {
8+
plugins: [
9+
[
10+
"@babel/transform-runtime",
11+
{
12+
corejs: 3,
13+
version: transformRuntimeVersion,
14+
},
15+
],
16+
],
17+
presets: [],
18+
};
19+
if (isTest) {
20+
config.presets.push(
21+
[
22+
"@babel/env",
23+
{
24+
bugfixes: true,
25+
useBuiltIns: "usage",
26+
corejs: 3,
27+
shippedProposals: true,
28+
},
29+
],
30+
[
31+
"@babel/typescript",
32+
{
33+
allowDeclareFields: true,
34+
onlyRemoveTypeImports: true,
35+
},
36+
]
37+
);
38+
} else {
39+
config.presets.push([
440
"@babel/env",
541
{
642
bugfixes: true,
7-
useBuiltIns: "usage",
8-
corejs: 3,
43+
useBuiltIns: false,
944
shippedProposals: true,
1045
},
11-
],
12-
[
13-
"@babel/typescript",
14-
{
15-
allowDeclareFields: true,
16-
onlyRemoveTypeImports: true,
17-
},
18-
],
19-
],
46+
]);
47+
}
48+
return config;
2049
};

0 commit comments

Comments
 (0)