babel-loader 8.2.2 → 8.2.3
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 +23 -1
- package/lib/cache.js +9 -1
- package/lib/index.js +14 -4
- package/package.json +2 -2
package/README.md
CHANGED
@@ -88,6 +88,8 @@ This loader also supports the following loader-specific option:
|
|
88
88
|
|
89
89
|
* `customize`: Default `null`. The path of a module that exports a `custom` callback [like the one that you'd pass to `.custom()`](#customized-loader). Since you already have to make a new file to use this, it is recommended that you instead use `.custom` to create a wrapper loader. Only use this if you _must_ continue using `babel-loader` directly, but still want to customize.
|
90
90
|
|
91
|
+
* `metadataSubscribers`: Default `[]`. Takes an array of context function names. E.g. if you passed ['myMetadataPlugin'], you'd assign a subscriber function to `context.myMetadataPlugin` within your webpack plugin's hooks & that function will be called with `metadata`.
|
92
|
+
|
91
93
|
## Troubleshooting
|
92
94
|
|
93
95
|
### babel-loader is slow!
|
@@ -108,7 +110,7 @@ For this, you can either use a combination of `test` and `not`, or [pass a funct
|
|
108
110
|
{
|
109
111
|
test: /\.m?js$/,
|
110
112
|
exclude: {
|
111
|
-
|
113
|
+
and: [/node_modules/], // Exclude libraries in node_modules ...
|
112
114
|
not: [
|
113
115
|
// Except for a few of them that needs to be transpiled because they use modern syntax
|
114
116
|
/unfetch/,
|
@@ -248,6 +250,26 @@ You will need to exclude them form `babel-loader`.
|
|
248
250
|
}
|
249
251
|
```
|
250
252
|
|
253
|
+
### Top level function (IIFE) is still arrow (on Webpack 5)
|
254
|
+
|
255
|
+
That function is injected by Webpack itself _after_ running `babel-loader`. By default Webpack asumes that your target environment supports some ES2015 features, but you can overwrite this behavior using the `output.environment` Webpack option ([documentation]((https://webpack.js.org/configuration/output/#outputenvironment)).
|
256
|
+
|
257
|
+
To avoid the top-level arrow function, you can use `output.environment.arrowFunction`:
|
258
|
+
|
259
|
+
```js
|
260
|
+
// webpack.config.js
|
261
|
+
module.exports = {
|
262
|
+
// ...
|
263
|
+
output: {
|
264
|
+
// ...
|
265
|
+
environment: {
|
266
|
+
// ...
|
267
|
+
arrowFunction: false, // <-- this line does the trick
|
268
|
+
},
|
269
|
+
},
|
270
|
+
};
|
271
|
+
```
|
272
|
+
|
251
273
|
## Customize config based on webpack target
|
252
274
|
|
253
275
|
Webpack supports bundling multiple [targets](https://webpack.js.org/concepts/targets/). For cases where you may want different Babel configurations for each target (like `web` _and_ `node`), this loader provides a `target` property via Babel's [caller](https://babeljs.io/docs/en/config-files#apicallercb) API.
|
package/lib/cache.js
CHANGED
@@ -91,7 +91,15 @@ const write = /*#__PURE__*/function () {
|
|
91
91
|
|
92
92
|
|
93
93
|
const filename = function (source, identifier, options) {
|
94
|
-
|
94
|
+
// md4 hashing is not supported starting with node v17.0.0
|
95
|
+
const majorNodeVersion = parseInt(process.versions.node.split(".")[0], 10);
|
96
|
+
let hashType = "md4";
|
97
|
+
|
98
|
+
if (majorNodeVersion >= 17) {
|
99
|
+
hashType = "md5";
|
100
|
+
}
|
101
|
+
|
102
|
+
const hash = crypto.createHash(hashType);
|
95
103
|
const contents = JSON.stringify({
|
96
104
|
source,
|
97
105
|
options,
|
package/lib/index.js
CHANGED
@@ -198,12 +198,22 @@ function _loader() {
|
|
198
198
|
});
|
199
199
|
} else {
|
200
200
|
result = yield transform(source, options);
|
201
|
-
} //
|
202
|
-
//
|
201
|
+
} // Availabe since Babel 7.12
|
202
|
+
// https://github.com/babel/babel/pull/11907
|
203
203
|
|
204
204
|
|
205
|
-
if (
|
206
|
-
this.addDependency(
|
205
|
+
if (config.files) {
|
206
|
+
config.files.forEach(configFile => this.addDependency(configFile));
|
207
|
+
} else {
|
208
|
+
// .babelrc.json
|
209
|
+
if (typeof config.babelrc === "string") {
|
210
|
+
this.addDependency(config.babelrc);
|
211
|
+
} // babel.config.js
|
212
|
+
|
213
|
+
|
214
|
+
if (config.config) {
|
215
|
+
this.addDependency(config.config);
|
216
|
+
}
|
207
217
|
}
|
208
218
|
|
209
219
|
if (result) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "babel-loader",
|
3
|
-
"version": "8.2.
|
3
|
+
"version": "8.2.3",
|
4
4
|
"description": "babel module loader for webpack",
|
5
5
|
"files": [
|
6
6
|
"lib"
|
@@ -44,7 +44,7 @@
|
|
44
44
|
"react-intl-webpack-plugin": "^0.3.0",
|
45
45
|
"rimraf": "^3.0.0",
|
46
46
|
"semver": "7.3.2",
|
47
|
-
"webpack": "^5.
|
47
|
+
"webpack": "^5.34.0"
|
48
48
|
},
|
49
49
|
"scripts": {
|
50
50
|
"clean": "rimraf lib/",
|