babel-loader 8.2.1 → 8.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -13
- package/lib/cache.js +3 -1
- package/lib/transform.js +3 -1
- package/package.json +3 -4
package/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
> This README is for babel-loader v8 + Babel v7
|
2
|
-
>
|
2
|
+
> If you are using legacy Babel v6, see the [7.x branch](https://github.com/babel/babel-loader/tree/7.x) docs
|
3
3
|
|
4
4
|
[](https://www.npmjs.com/package/babel-loader)
|
5
5
|
[](https://codecov.io/gh/babel/babel-loader)
|
@@ -21,7 +21,7 @@ This package allows transpiling JavaScript files using [Babel](https://github.co
|
|
21
21
|
|
22
22
|
<h2 align="center">Install</h2>
|
23
23
|
|
24
|
-
> webpack 4.x | babel-loader 8.x | babel 7.x
|
24
|
+
> webpack `4.x || 5.x` | babel-loader 8.x | babel 7.x
|
25
25
|
|
26
26
|
```bash
|
27
27
|
npm install -D babel-loader @babel/core @babel/preset-env webpack
|
@@ -38,11 +38,13 @@ module: {
|
|
38
38
|
rules: [
|
39
39
|
{
|
40
40
|
test: /\.m?js$/,
|
41
|
-
exclude: /
|
41
|
+
exclude: /node_modules/,
|
42
42
|
use: {
|
43
43
|
loader: 'babel-loader',
|
44
44
|
options: {
|
45
|
-
presets: [
|
45
|
+
presets: [
|
46
|
+
['@babel/preset-env', { targets: "defaults" }]
|
47
|
+
]
|
46
48
|
}
|
47
49
|
}
|
48
50
|
}
|
@@ -54,19 +56,21 @@ module: {
|
|
54
56
|
|
55
57
|
See the `babel` [options](https://babeljs.io/docs/en/options).
|
56
58
|
|
57
|
-
You can pass options to the loader by using the [`options`](https://webpack.js.org/configuration/module/#
|
59
|
+
You can pass options to the loader by using the [`options`](https://webpack.js.org/configuration/module/#ruleoptions--rulequery) property:
|
58
60
|
|
59
61
|
```javascript
|
60
62
|
module: {
|
61
63
|
rules: [
|
62
64
|
{
|
63
65
|
test: /\.m?js$/,
|
64
|
-
exclude: /
|
66
|
+
exclude: /node_modules/,
|
65
67
|
use: {
|
66
68
|
loader: 'babel-loader',
|
67
69
|
options: {
|
68
|
-
presets: [
|
69
|
-
|
70
|
+
presets: [
|
71
|
+
['@babel/preset-env', { targets: "defaults" }]
|
72
|
+
],
|
73
|
+
plugins: ['@babel/plugin-proposal-class-properties']
|
70
74
|
}
|
71
75
|
}
|
72
76
|
}
|
@@ -94,6 +98,35 @@ To exclude `node_modules`, see the `exclude` option in the `loaders` config as d
|
|
94
98
|
|
95
99
|
You can also speed up babel-loader by as much as 2x by using the `cacheDirectory` option. This will cache transformations to the filesystem.
|
96
100
|
|
101
|
+
### Some files in my node_modules are not transpiled for IE 11
|
102
|
+
|
103
|
+
Although we typically recommend not compiling `node_modules`, you may need to when using libraries that do not support IE 11.
|
104
|
+
|
105
|
+
For this, you can either use a combination of `test` and `not`, or [pass a function](https://webpack.js.org/configuration/module/#condition) to your `exclude` option. You can also use negative lookahead regex as suggested [here](https://github.com/webpack/webpack/issues/2031#issuecomment-294706065).
|
106
|
+
|
107
|
+
```javascript
|
108
|
+
{
|
109
|
+
test: /\.m?js$/,
|
110
|
+
exclude: {
|
111
|
+
test: /node_modules/, // Exclude libraries in node_modules ...
|
112
|
+
not: [
|
113
|
+
// Except for a few of them that needs to be transpiled because they use modern syntax
|
114
|
+
/unfetch/,
|
115
|
+
/d3-array|d3-scale/,
|
116
|
+
/@hapi[\\/]joi-date/,
|
117
|
+
]
|
118
|
+
},
|
119
|
+
use: {
|
120
|
+
loader: 'babel-loader',
|
121
|
+
options: {
|
122
|
+
presets: [
|
123
|
+
['@babel/preset-env', { targets: "ie 11" }]
|
124
|
+
]
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}
|
128
|
+
```
|
129
|
+
|
97
130
|
### Babel is injecting helpers into each file and bloating my code!
|
98
131
|
|
99
132
|
Babel uses very small helpers for common functions such as `_extend`. By default, this will be added to every file that requires it.
|
@@ -112,11 +145,13 @@ rules: [
|
|
112
145
|
// require the runtime instead of inlining it.
|
113
146
|
{
|
114
147
|
test: /\.m?js$/,
|
115
|
-
exclude: /
|
148
|
+
exclude: /node_modules/,
|
116
149
|
use: {
|
117
150
|
loader: 'babel-loader',
|
118
151
|
options: {
|
119
|
-
presets: [
|
152
|
+
presets: [
|
153
|
+
['@babel/preset-env', { targets: "defaults" }]
|
154
|
+
],
|
120
155
|
plugins: ['@babel/plugin-transform-runtime']
|
121
156
|
}
|
122
157
|
}
|
@@ -202,9 +237,9 @@ You will need to exclude them form `babel-loader`.
|
|
202
237
|
"loader": "babel-loader",
|
203
238
|
"options": {
|
204
239
|
"exclude": [
|
205
|
-
// \\ for Windows,
|
206
|
-
/node_modules[
|
207
|
-
/node_modules[
|
240
|
+
// \\ for Windows, / for macOS and Linux
|
241
|
+
/node_modules[\\/]core-js/,
|
242
|
+
/node_modules[\\/]webpack[\\/]buildin/,
|
208
243
|
],
|
209
244
|
"presets": [
|
210
245
|
"@babel/preset-env"
|
package/lib/cache.js
CHANGED
@@ -25,7 +25,9 @@ const crypto = require("crypto");
|
|
25
25
|
|
26
26
|
const findCacheDir = require("find-cache-dir");
|
27
27
|
|
28
|
-
const
|
28
|
+
const {
|
29
|
+
promisify
|
30
|
+
} = require("util");
|
29
31
|
|
30
32
|
const transform = require("./transform"); // Lazily instantiated when needed
|
31
33
|
|
package/lib/transform.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "babel-loader",
|
3
|
-
"version": "8.2.
|
3
|
+
"version": "8.2.2",
|
4
4
|
"description": "babel module loader for webpack",
|
5
5
|
"files": [
|
6
6
|
"lib"
|
@@ -10,10 +10,9 @@
|
|
10
10
|
"node": ">= 8.9"
|
11
11
|
},
|
12
12
|
"dependencies": {
|
13
|
-
"find-cache-dir": "^
|
13
|
+
"find-cache-dir": "^3.3.1",
|
14
14
|
"loader-utils": "^1.4.0",
|
15
|
-
"make-dir": "^
|
16
|
-
"pify": "^4.0.1",
|
15
|
+
"make-dir": "^3.1.0",
|
17
16
|
"schema-utils": "^2.6.5"
|
18
17
|
},
|
19
18
|
"peerDependencies": {
|