Skip to content

Commit

Permalink
Give helpful feedback when used with an old Babel version.
Browse files Browse the repository at this point in the history
  • Loading branch information
loganfsmyth committed Sep 5, 2018
1 parent b74672e commit 3bfff92
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@

## Install

```
For Babel 7.x and grunt-babel v8
```sh
$ yarn add --dev grunt-babel @babel/core @babel/preset-env
```

For Babel 6.x and grunt-babel v7
```sh
$ yarn add --dev grunt-babel@7 @babel-core babel-preset-env
```
Note: See the [7.x branch](https://github.com/babel/grunt-babel/tree/7.x) for more examples of
usage of Babel 6.x. This README is primarily applicable for Babel 7.x

## Usage

```js
Expand Down
22 changes: 21 additions & 1 deletion tasks/babel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
"use strict";
const path = require("path");
const babel = require("@babel/core");

let babel;
try {
babel = require("@babel/core");
} catch (err) {
if (err.code === "MODULE_NOT_FOUND") {
err.message +=
"\n grunt-babel@8 requires Babel 7.x (the package '@babel/core'). " +
"If you'd like to use Babel 6.x ('babel-core'), you should install 'grunt-babel@7'.";
}
throw err;
}

// Since we've got the reverse bridge package at @babel/core@6.x, give
// people useful feedback if they try to use it alongside babel-loader.
if (/^6\./.test(babel.version)) {
throw new Error(
"\n grunt-babel@8 will not work with the '@babel/core@6' bridge package. " +
"If you want to use Babel 6.x, install 'grunt-babel@7'."
);
}

module.exports = function(grunt) {
grunt.registerMultiTask(
Expand Down

0 comments on commit 3bfff92

Please sign in to comment.