Skip to content

Commit 771f71b

Browse files
committed
feat(pgk): use es for modern js, change module field for es5 + esmodule
Fixes #78
1 parent 4f51a68 commit 771f71b

File tree

5 files changed

+27
-22
lines changed

5 files changed

+27
-22
lines changed

README.md

+6-14
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,17 @@ npm install autobind-decorator
2626

2727
We target IE11+ browsers (see [out browserslist](./src/browserslist)) with the following caveats:
2828

29-
`main` entry is in ES5
29+
`main`: ES5
3030

31-
`module` entry is in ES6+ (notably ES modules to enable tree shaking)
31+
`module`: ES5 + ES modules to enable tree shaking
3232

33-
#### Dev
34-
35-
node 8.10+ with latest npm
33+
`es`: modern JS
3634

37-
## ES5 and uglify users
35+
On consuming modern JS, you can transpile the script to your target environment ([@babel/preset-env](https://babeljs.io/docs/en/babel-preset-env) is recommended) to minimise the cost. For more details, please read https://babeljs.io/blog/2018/06/26/on-consuming-and-publishing-es2015+-packages.
3836

39-
Starting from v2.2, we added `module` entry in package.json and kept `main` entry as is. `module` entry is for those who wish to use modern JavaScript (notably ES modules to enable tree shaking). If your environment doesn't understand the modern syntax, you can configure your tool to read the ES5 script via the `main` entry. EG: with webpack, you could do
40-
41-
```js
42-
resolve: {
43-
mainFields: ['main']
44-
}
45-
```
37+
#### Dev
4638

47-
You could also transpile the script to your target environment ([@babel/preset-env](https://babeljs.io/docs/en/babel-preset-env) is recommended). For more details, please read https://babeljs.io/blog/2018/06/26/on-consuming-and-publishing-es2015+-packages.
39+
node 8.10+ with latest npm
4840

4941
## Babel 6 users (legacy only)
5042

package.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
"name": "autobind-decorator",
33
"version": "2.3.1",
44
"description": "Decorator for binding method to an object",
5-
"main": "lib/index.js",
6-
"module": "src/index.js",
5+
"main": "lib/cjs/index.js",
6+
"module": "lib/esm/index.js",
7+
"es": "src/index.js",
78
"types": "index.d.ts",
89
"scripts": {
910
"clean": "rm -rf lib",
10-
"prepare": " npm run clean && babel src --out-dir lib --ignore \"src/__tests__/*.js\"",
11+
"build:es5": "babel src --out-dir lib/cjs --ignore \"src/__tests__/*.js\"",
12+
"build:module": "babel --no-babelrc --config-file ./src/.babelrc.es.js src --out-dir lib/esm --ignore \"src/__tests__/*.js\"",
13+
"build": "npm run build:es5 && npm run build:module",
14+
"prepare": " npm run clean && npm run build",
1115
"lint": "xo",
1216
"test": "jest --coverage",
1317
"release": "standard-version",

src/.babelrc

-5
This file was deleted.

src/.babelrc.es.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
"presets": [
3+
["@babel/preset-env",
4+
{
5+
"modules": false,
6+
}
7+
]
8+
]
9+
}

src/.babelrc.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
"presets": [
3+
["@babel/preset-env"]
4+
]
5+
}

0 commit comments

Comments
 (0)