babel-loader 8.0.6 → 8.1.0

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 CHANGED
@@ -84,7 +84,7 @@ This loader also supports the following loader-specific option:
84
84
 
85
85
  * `cacheCompression`: Default `true`. When set, each Babel transform output will be compressed with Gzip. If you want to opt-out of cache compression, set it to `false` -- your project may benefit from this if it transpiles thousands of files.
86
86
 
87
- * `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 is you _must_ continue using `babel-loader` directly, but still want to customize.
87
+ * `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.
88
88
 
89
89
  ## Troubleshooting
90
90
 
@@ -193,6 +193,37 @@ In the case one of your dependencies is installing `babel` and you cannot uninst
193
193
  }
194
194
  ```
195
195
 
196
+ ## Customize config based on webpack target
197
+
198
+ 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.
199
+
200
+ For example, to change the environment targets passed to `@babel/preset-env` based on the webpack target:
201
+
202
+ ```javascript
203
+ // babel.config.js
204
+
205
+ module.exports = api => {
206
+ return {
207
+ plugins: [
208
+ "@babel/plugin-proposal-nullish-coalescing-operator",
209
+ "@babel/plugin-proposal-optional-chaining"
210
+ ],
211
+ presets: [
212
+ [
213
+ "@babel/preset-env",
214
+ {
215
+ useBuiltIns: "entry",
216
+ // caller.target will be the same as the target option from webpack
217
+ targets: api.caller(caller => caller && caller.target === "node")
218
+ ? { node: "current" }
219
+ : { chrome: "58", ie: "11" }
220
+ }
221
+ ]
222
+ ]
223
+ }
224
+ }
225
+ ```
226
+
196
227
  ## Customized Loader
197
228
 
198
229
  `babel-loader` exposes a loader-builder utility that allows users to add custom handling
package/lib/index.js CHANGED
@@ -32,12 +32,16 @@ const transform = require("./transform");
32
32
 
33
33
  const injectCaller = require("./injectCaller");
34
34
 
35
+ const schema = require("./schema");
36
+
35
37
  const {
36
38
  isAbsolute
37
39
  } = require("path");
38
40
 
39
41
  const loaderUtils = require("loader-utils");
40
42
 
43
+ const validateOptions = require("schema-utils");
44
+
41
45
  function subscribe(subscriber, metadata, context) {
42
46
  if (context[subscriber]) {
43
47
  context[subscriber](metadata);
@@ -64,6 +68,9 @@ function _loader() {
64
68
  _loader = _asyncToGenerator(function* (source, inputSourceMap, overrides) {
65
69
  const filename = this.resourcePath;
66
70
  let loaderOptions = loaderUtils.getOptions(this) || {};
71
+ validateOptions(schema, loaderOptions, {
72
+ name: "Babel loader"
73
+ });
67
74
 
68
75
  if (loaderOptions.customize != null) {
69
76
  if (typeof loaderOptions.customize !== "string") {
@@ -141,7 +148,7 @@ function _loader() {
141
148
  throw new Error(`babel-loader ^8.0.0-beta.3 requires @babel/core@7.0.0-beta.41, but ` + `you appear to be using "${babel.version}". Either update your ` + `@babel/core version, or pin you babel-loader version to 8.0.0-beta.2`);
142
149
  }
143
150
 
144
- const config = babel.loadPartialConfig(injectCaller(programmaticOptions));
151
+ const config = babel.loadPartialConfig(injectCaller(programmaticOptions, this.target));
145
152
 
146
153
  if (config) {
147
154
  let options = config.options;
@@ -2,14 +2,21 @@
2
2
 
3
3
  const babel = require("@babel/core");
4
4
 
5
- module.exports = function injectCaller(opts) {
5
+ module.exports = function injectCaller(opts, target) {
6
6
  if (!supportsCallerOption()) return opts;
7
7
  return Object.assign({}, opts, {
8
8
  caller: Object.assign({
9
9
  name: "babel-loader",
10
+ // Provide plugins with insight into webpack target.
11
+ // https://github.com/babel/babel-loader/issues/787
12
+ target,
10
13
  // Webpack >= 2 supports ESM and dynamic import.
11
14
  supportsStaticESM: true,
12
- supportsDynamicImport: true
15
+ supportsDynamicImport: true,
16
+ // Webpack 5 supports TLA behind a flag. We enable it by default
17
+ // for Babel, and then webpack will throw an error if the experimental
18
+ // flag isn't enabled.
19
+ supportsTopLevelAwait: true
13
20
  }, opts.caller)
14
21
  });
15
22
  }; // TODO: We can remove this eventually, I'm just adding it so that people have
@@ -0,0 +1,28 @@
1
+ {
2
+ "type": "object",
3
+ "properties": {
4
+ "cacheDirectory": {
5
+ "oneOf": [
6
+ {
7
+ "type": "boolean"
8
+ },
9
+ {
10
+ "type": "string"
11
+ }
12
+ ],
13
+ "default": false
14
+ },
15
+ "cacheIdentifier": {
16
+ "type": "string"
17
+ },
18
+ "cacheCompression": {
19
+ "type": "boolean",
20
+ "default": true
21
+ },
22
+ "customize": {
23
+ "type": "string",
24
+ "default": null
25
+ }
26
+ },
27
+ "additionalProperties": true
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-loader",
3
- "version": "8.0.6",
3
+ "version": "8.1.0",
4
4
  "description": "babel module loader for webpack",
5
5
  "files": [
6
6
  "lib"
@@ -10,10 +10,11 @@
10
10
  "node": ">= 6.9"
11
11
  },
12
12
  "dependencies": {
13
- "find-cache-dir": "^2.0.0",
14
- "loader-utils": "^1.0.2",
15
- "mkdirp": "^0.5.1",
16
- "pify": "^4.0.1"
13
+ "find-cache-dir": "^2.1.0",
14
+ "loader-utils": "^1.4.0",
15
+ "mkdirp": "^0.5.3",
16
+ "pify": "^4.0.1",
17
+ "schema-utils": "^2.6.5"
17
18
  },
18
19
  "peerDependencies": {
19
20
  "@babel/core": "^7.0.0",
@@ -23,29 +24,29 @@
23
24
  "@babel/cli": "^7.2.0",
24
25
  "@babel/core": "^7.2.0",
25
26
  "@babel/preset-env": "^7.2.0",
26
- "ava": "^1.1.0",
27
+ "ava": "^2.4.0",
27
28
  "babel-eslint": "^10.0.1",
28
29
  "babel-plugin-istanbul": "^5.1.0",
29
- "babel-plugin-react-intl": "^3.0.1",
30
- "cross-env": "^5.2.0",
31
- "eslint": "^5.9.0",
30
+ "babel-plugin-react-intl": "^4.1.19",
31
+ "cross-env": "^6.0.0",
32
+ "eslint": "^6.5.1",
32
33
  "eslint-config-babel": "^9.0.0",
33
- "eslint-config-prettier": "^4.1.0",
34
- "eslint-plugin-flowtype": "^3.2.0",
34
+ "eslint-config-prettier": "^6.3.0",
35
+ "eslint-plugin-flowtype": "^4.3.0",
35
36
  "eslint-plugin-prettier": "^3.0.0",
36
- "husky": "^1.2.0",
37
- "lint-staged": "^8.1.0",
37
+ "husky": "^3.0.7",
38
+ "lint-staged": "^9.4.1",
38
39
  "nyc": "^14.1.1",
39
40
  "prettier": "^1.15.3",
40
41
  "react": "^16.0.0",
41
- "react-intl": "^2.1.2",
42
+ "react-intl": "^3.3.2",
42
43
  "react-intl-webpack-plugin": "^0.3.0",
43
- "rimraf": "^2.4.3",
44
+ "rimraf": "^3.0.0",
44
45
  "webpack": "^4.0.0"
45
46
  },
46
47
  "scripts": {
47
48
  "clean": "rimraf lib/",
48
- "build": "babel src/ --out-dir lib/",
49
+ "build": "babel src/ --out-dir lib/ --copy-files",
49
50
  "format": "prettier --write --trailing-comma all 'src/**/*.js' 'test/**/*.test.js' 'test/helpers/*.js' && prettier --write --trailing-comma es5 'scripts/*.js'",
50
51
  "lint": "eslint src test",
51
52
  "precommit": "lint-staged",
@@ -90,6 +91,9 @@
90
91
  "!test/fixtures/**/*",
91
92
  "!test/helpers/**/*"
92
93
  ],
94
+ "helpers": [
95
+ "**/helpers/**/*"
96
+ ],
93
97
  "sources": [
94
98
  "src/**/*.js"
95
99
  ]