Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: babel/babel-loader
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v8.0.6
Choose a base ref
...
head repository: babel/babel-loader
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v8.1.0
Choose a head ref
  • 18 commits
  • 10 files changed
  • 9 contributors

Commits on Jul 15, 2019

  1. Bump lodash from 4.17.11 to 4.17.14 (#800)

    Bumps [lodash](https://github.com/lodash/lodash) from 4.17.11 to 4.17.14.
    - [Release notes](https://github.com/lodash/lodash/releases)
    - [Commits](lodash/lodash@4.17.11...4.17.14)
    
    Signed-off-by: dependabot[bot] <[email protected]>
    dependabot[bot] authored and danez committed Jul 15, 2019
    Copy the full SHA
    799b574 View commit details
  2. Bump lodash.merge from 4.6.1 to 4.6.2 (#801)

    Bumps [lodash.merge](https://github.com/lodash/lodash) from 4.6.1 to 4.6.2.
    - [Release notes](https://github.com/lodash/lodash/releases)
    - [Commits](https://github.com/lodash/lodash/commits)
    
    Signed-off-by: dependabot[bot] <[email protected]>
    dependabot[bot] authored and danez committed Jul 15, 2019
    Copy the full SHA
    473d03b View commit details

Commits on Aug 29, 2019

  1. Copy the full SHA
    38a8c64 View commit details
  2. Copy the full SHA
    a961168 View commit details

Commits on Oct 1, 2019

  1. Verified

    This commit was signed with the committer’s verified signature. The key has expired and has been revoked.
    danez Daniel Tschinder
    Copy the full SHA
    26aa687 View commit details
  2. chore: Upgrade more dev dependencies

    Also do not run travis on node 6
    danez committed Oct 1, 2019

    Verified

    This commit was signed with the committer’s verified signature. The key has expired and has been revoked.
    danez Daniel Tschinder
    Copy the full SHA
    26d1676 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature. The key has expired and has been revoked.
    danez Daniel Tschinder
    Copy the full SHA
    15df92f View commit details

Commits on Oct 29, 2019

  1. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    8a0a25a View commit details

Commits on Dec 17, 2019

  1. docs(readme): fix typo (#818)

    frederickfogerty authored and JLHwung committed Dec 17, 2019
    Copy the full SHA
    758d4b5 View commit details

Commits on Jan 30, 2020

  1. Copy the full SHA
    a967311 View commit details
  2. Merge pull request #821 from PatNeedham/docs/contributing-typo

    docs(contributing): fix typo
    nicolo-ribaudo authored Jan 30, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    8b47312 View commit details

Commits on Feb 21, 2020

  1. Add schema validation (#822)

    * Add `schema-utils`
    
    * Add schema validation
    ogonkov authored Feb 21, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5f55638 View commit details
  2. Update src/injectCaller.js

    JLHwung authored Feb 21, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1c35731 View commit details

Commits on Feb 26, 2020

  1. Merge pull request #814 from nicolo-ribaudo/tla

    Add supportsTopLevelAwait to caller
    nicolo-ribaudo authored Feb 26, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b568420 View commit details

Commits on Feb 28, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    13a8238 View commit details

Commits on Mar 14, 2020

  1. Bump acorn from 6.3.0 to 6.4.1 (#828)

    Bumps [acorn](https://github.com/acornjs/acorn) from 6.3.0 to 6.4.1.
    - [Release notes](https://github.com/acornjs/acorn/releases)
    - [Commits](acornjs/acorn@6.3.0...6.4.1)
    
    Signed-off-by: dependabot[bot] <[email protected]>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Mar 14, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ecb2b02 View commit details

Commits on Mar 20, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0817bb6 View commit details
  2. 8.1.0

    existentialism committed Mar 20, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    existentialism Brian Ng
    Copy the full SHA
    3ff9926 View commit details
Showing with 2,041 additions and 1,418 deletions.
  1. +0 −1 .travis.yml
  2. +2 −2 CONTRIBUTING.md
  3. +32 −1 README.md
  4. +0 −1 appveyor.yml
  5. +20 −16 package.json
  6. +9 −1 src/index.js
  7. +10 −1 src/injectCaller.js
  8. +28 −0 src/schema.json
  9. +1 −1 test/cache.test.js
  10. +1,939 −1,394 yarn.lock
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ node_js:
- "12"
- "10"
- "8"
- "6"

env:
- JOB=test
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@

I'm not too strict with coding styles.

While personally I'm using the [node-style-guide](https://github.com/felixge/node-style-guide), as long you don't to something too weird or fancy, that's probably ok.
While personally I'm using the [node-style-guide](https://github.com/felixge/node-style-guide), as long you don't do something too weird or fancy, that's probably ok.

If, however, you want to ensure that you're following the node style guide, you can use [JSCS](https://github.com/jscs-dev/node-jscs). The rules are already set on the [.jscsrc](https://github.com/babel/babel-loader/blob/master/.jscsrc) file and there's most likely some [package](http://jscs.info/overview.html#friendly-packages) to your editor already.

Documentation, wether in the state of JavaDoc or simple line comments are always welcome.
Documentation, whether in the state of JavaDoc or simple line comments are always welcome.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ This loader also supports the following loader-specific option:

* `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.

* `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.
* `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.

## Troubleshooting

@@ -193,6 +193,37 @@ In the case one of your dependencies is installing `babel` and you cannot uninst
}
```

## Customize config based on webpack target

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.

For example, to change the environment targets passed to `@babel/preset-env` based on the webpack target:

```javascript
// babel.config.js

module.exports = api => {
return {
plugins: [
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-optional-chaining"
],
presets: [
[
"@babel/preset-env",
{
useBuiltIns: "entry",
// caller.target will be the same as the target option from webpack
targets: api.caller(caller => caller && caller.target === "node")
? { node: "current" }
: { chrome: "58", ie: "11" }
}
]
]
}
}
```

## Customized Loader

`babel-loader` exposes a loader-builder utility that allows users to add custom handling
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ environment:
- nodejs_version: "12"
- nodejs_version: "10"
- nodejs_version: "8"
- nodejs_version: "6"

install:
- ps: Install-Product node $env:nodejs_version
36 changes: 20 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-loader",
"version": "8.0.6",
"version": "8.1.0",
"description": "babel module loader for webpack",
"files": [
"lib"
@@ -10,10 +10,11 @@
"node": ">= 6.9"
},
"dependencies": {
"find-cache-dir": "^2.0.0",
"loader-utils": "^1.0.2",
"mkdirp": "^0.5.1",
"pify": "^4.0.1"
"find-cache-dir": "^2.1.0",
"loader-utils": "^1.4.0",
"mkdirp": "^0.5.3",
"pify": "^4.0.1",
"schema-utils": "^2.6.5"
},
"peerDependencies": {
"@babel/core": "^7.0.0",
@@ -23,29 +24,29 @@
"@babel/cli": "^7.2.0",
"@babel/core": "^7.2.0",
"@babel/preset-env": "^7.2.0",
"ava": "^1.1.0",
"ava": "^2.4.0",
"babel-eslint": "^10.0.1",
"babel-plugin-istanbul": "^5.1.0",
"babel-plugin-react-intl": "^3.0.1",
"cross-env": "^5.2.0",
"eslint": "^5.9.0",
"babel-plugin-react-intl": "^4.1.19",
"cross-env": "^6.0.0",
"eslint": "^6.5.1",
"eslint-config-babel": "^9.0.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-flowtype": "^3.2.0",
"eslint-config-prettier": "^6.3.0",
"eslint-plugin-flowtype": "^4.3.0",
"eslint-plugin-prettier": "^3.0.0",
"husky": "^1.2.0",
"lint-staged": "^8.1.0",
"husky": "^3.0.7",
"lint-staged": "^9.4.1",
"nyc": "^14.1.1",
"prettier": "^1.15.3",
"react": "^16.0.0",
"react-intl": "^2.1.2",
"react-intl": "^3.3.2",
"react-intl-webpack-plugin": "^0.3.0",
"rimraf": "^2.4.3",
"rimraf": "^3.0.0",
"webpack": "^4.0.0"
},
"scripts": {
"clean": "rimraf lib/",
"build": "babel src/ --out-dir lib/",
"build": "babel src/ --out-dir lib/ --copy-files",
"format": "prettier --write --trailing-comma all 'src/**/*.js' 'test/**/*.test.js' 'test/helpers/*.js' && prettier --write --trailing-comma es5 'scripts/*.js'",
"lint": "eslint src test",
"precommit": "lint-staged",
@@ -90,6 +91,9 @@
"!test/fixtures/**/*",
"!test/helpers/**/*"
],
"helpers": [
"**/helpers/**/*"
],
"sources": [
"src/**/*.js"
]
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -23,9 +23,11 @@ const { version } = require("../package.json");
const cache = require("./cache");
const transform = require("./transform");
const injectCaller = require("./injectCaller");
const schema = require("./schema");

const { isAbsolute } = require("path");
const loaderUtils = require("loader-utils");
const validateOptions = require("schema-utils");

function subscribe(subscriber, metadata, context) {
if (context[subscriber]) {
@@ -54,6 +56,10 @@ async function loader(source, inputSourceMap, overrides) {

let loaderOptions = loaderUtils.getOptions(this) || {};

validateOptions(schema, loaderOptions, {
name: "Babel loader",
});

if (loaderOptions.customize != null) {
if (typeof loaderOptions.customize !== "string") {
throw new Error(
@@ -152,7 +158,9 @@ async function loader(source, inputSourceMap, overrides) {
);
}

const config = babel.loadPartialConfig(injectCaller(programmaticOptions));
const config = babel.loadPartialConfig(
injectCaller(programmaticOptions, this.target),
);
if (config) {
let options = config.options;
if (overrides && overrides.config) {
11 changes: 10 additions & 1 deletion src/injectCaller.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
const babel = require("@babel/core");

module.exports = function injectCaller(opts) {
module.exports = function injectCaller(opts, target) {
if (!supportsCallerOption()) return opts;

return Object.assign({}, opts, {
caller: Object.assign(
{
name: "babel-loader",

// Provide plugins with insight into webpack target.
// https://github.com/babel/babel-loader/issues/787
target,

// Webpack >= 2 supports ESM and dynamic import.
supportsStaticESM: true,
supportsDynamicImport: true,

// Webpack 5 supports TLA behind a flag. We enable it by default
// for Babel, and then webpack will throw an error if the experimental
// flag isn't enabled.
supportsTopLevelAwait: true,
},
opts.caller,
),
28 changes: 28 additions & 0 deletions src/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"type": "object",
"properties": {
"cacheDirectory": {
"oneOf": [
{
"type": "boolean"
},
{
"type": "string"
}
],
"default": false
},
"cacheIdentifier": {
"type": "string"
},
"cacheCompression": {
"type": "boolean",
"default": true
},
"customize": {
"type": "string",
"default": null
}
},
"additionalProperties": true
}
2 changes: 1 addition & 1 deletion test/cache.test.js
Original file line number Diff line number Diff line change
@@ -191,7 +191,7 @@ test.serial.cb(
},
);

test.cb.skip("should read from cache directory if cached file exists", t => {
test.cb("should read from cache directory if cached file exists", t => {
const config = Object.assign({}, globalConfig, {
output: {
path: t.context.directory,
Loading