Skip to content

Commit

Permalink
Merge branch '7.0'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
danez committed Apr 21, 2017
2 parents 74ff2e6 + 2204871 commit 174cb10
Show file tree
Hide file tree
Showing 21 changed files with 1,769 additions and 1,386 deletions.
5 changes: 2 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"presets": [
["latest", { "es2015": { "loose": true } }]
["env", { "loose": true, "targets": { "node": 4 } }]
],
"env": {
"test": {
"plugins": ["istanbul"]
}
},
"comments": false
}
}
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
},
"extends": [
"eslint-config-babel"
]
],
"rules": {
"arrow-parens": "off"
}
}
22 changes: 11 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ node_js:
- "6"
- "4"

env:
- JOB=test

matrix:
fast_finish: true
include:
- node_js: "lts/*"
env: WEBPACK_VERSION="1"
- node_js: "lts/*"
env: LINT=true
- node_js: "0.10"
env: WEBPACK_VERSION="1"
- node_js: "0.12"
env: WEBPACK_VERSION="1"
env: JOB=lint

before_script:
- 'if [ "$WEBPACK_VERSION" ]; then npm install webpack@$WEBPACK_VERSION; fi'
- 'if [ "$JOB" = "test" ]; then BABEL_ENV=test yarn run build; fi'

script:
- 'if [ -n "${LINT-}" ]; then npm run lint ; fi'
- 'if [ -z "${LINT-}" ]; then npm run test-ci ; fi'
- 'if [ "$JOB" = "test" ]; then yarn test-only; fi'
- 'if [ "$JOB" = "lint" ]; then yarn run lint; fi'
after_success:
- npm run coverage
- bash <(curl -s https://codecov.io/bash) -f coverage/coverage-final.json
133 changes: 55 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
# babel-loader
[![NPM Status](https://img.shields.io/npm/v/babel-loader.svg?style=flat)](https://www.npmjs.com/package/babel-loader)
[![Build Status](https://travis-ci.org/babel/babel-loader.svg?branch=master)](https://travis-ci.org/babel/babel-loader)
[![Build Status](https://ci.appveyor.com/api/projects/status/vgtpr2i5bykgyuqo/branch/master?svg=true)](https://ci.appveyor.com/project/danez/babel-loader/branch/master)
[![codecov](https://codecov.io/gh/babel/babel-loader/branch/master/graph/badge.svg)](https://codecov.io/gh/babel/babel-loader)
> Babel is a compiler for writing next generation JavaScript.

This package allows transpiling JavaScript files using [Babel](https://github.com/babel/babel) and [webpack](https://github.com/webpack/webpack).
<div align="center">
<a href="https://github.com/babel/babel/">
<img width="200" height="200" src="https://rawgit.com/babel/logo/master/babel.svg">
</a>
<a href="https://github.com/webpack/webpack">
<img width="200" height="200" src="https://webpack.js.org/assets/icon-square-big.svg">
</a>
<h1>Babel Loader</h1>
</div>

__Notes:__ Issues with the output should be reported on the babel [issue tracker](https://github.com/babel/babel/issues);
This package allows transpiling JavaScript files using [Babel](https://github.com/babel/babel) and [webpack](https://github.com/webpack/webpack).

## Installation
__Notes:__ Issues with the output should be reported on the babel [issue tracker](https://github.com/babel/babel/issues);

```bash
npm install babel-loader babel-core babel-preset-env webpack --save-dev
```
<h2 align="center">Install</h2>

or
> webpack 1.x | babel-loader <= 6.x
>
> webpack 2.x | babel-loader >= 7.x (recommended) (^6.2.10 will also work, but with deprecation warnings)
```bash
yarn add babel-loader babel-core babel-preset-env webpack --dev
```

__Note:__ [npm](https://npmjs.com) deprecated [auto-installing of peerDependencies](https://github.com/npm/npm/issues/6565) since npm@3, so required peer dependencies like babel-core and webpack must be listed explicitly in your `package.json`.
We recommend using yarn, but you can also still use npm:

__Note:__ If you're upgrading from babel 5 to babel 6, please take a look [at this guide](https://medium.com/@malyw/how-to-update-babel-5-x-6-x-d828c230ec53#.yqxukuzdk).
```bash
npm install --save-dev babel-loader babel-core babel-preset-env webpack
```

## Usage
<h2 align="center">Usage</h2>

[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
[Documentation: Using loaders](https://webpack.js.org/loaders/)

Within your webpack configuration object, you'll need to add the babel-loader to the list of modules, like so:
Within your webpack configuration object, you'll need to add the babel-loader to the list of modules, like so:

```javascript
```javascript
module: {
rules: [
{
Expand All @@ -46,29 +54,16 @@ module: {
}
]
}
```
```

### Options

See the `babel` [options](http://babeljs.io/docs/usage/options/).
See the `babel` [options](https://babeljs.io/docs/usage/api/#options).

You can pass options to the loader by writing them as a [query string](https://github.com/webpack/loader-utils):

```javascript
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader?presets[]=env'
}
]
}
```

or by using the [query property](https://webpack.github.io/docs/using-loaders.html#query-parameters):
You can pass options to the loader by using the [options property](https://webpack.js.org/configuration/module/#rule-options-rule-query):

```javascript
```javascript
module: {
rules: [
{
Expand All @@ -77,83 +72,65 @@ module: {
use: {
loader: 'babel-loader',
options: {
presets: ['env']
presets: ['env'],
plugins: [require('babel-plugin-transform-object-rest-spread')]
}
}
}
]
}
```

or by using global options:

> Be aware that this only works in webpack 1 and not in version 2.

```javascript
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader'
}
]
},
babel: {
presets: ['es2015']
}
```

This loader also supports the following loader-specific option:
```

* `cacheDirectory`: Default `false`. When set, the given directory will be used to cache the results of the loader. Future webpack builds will attempt to read from the cache to avoid needing to run the potentially expensive Babel recompilation process on each run. If the value is blank (`loader: 'babel-loader?cacheDirectory'`) or `true` (`loader: babel-loader?cacheDirectory=true`) the loader will use the default cache directory in `node_modules/.cache/babel-loader` or fallback to the default OS temporary file directory if no `node_modules` folder could be found in any root directory.
This loader also supports the following loader-specific option:

* `cacheIdentifier`: Default is a string composed by the babel-core's version, the babel-loader's version, the contents of .babelrc file if it exists and the value of the environment variable `BABEL_ENV` with a fallback to the `NODE_ENV` environment variable. This can be set to a custom value to force cache busting if the identifier changes.
* `cacheDirectory`: Default `false`. When set, the given directory will be used to cache the results of the loader. Future webpack builds will attempt to read from the cache to avoid needing to run the potentially expensive Babel recompilation process on each run. If the value is blank (`loader: 'babel-loader?cacheDirectory'`) or `true` (`loader: babel-loader?cacheDirectory=true`) the loader will use the default cache directory in `node_modules/.cache/babel-loader` or fallback to the default OS temporary file directory if no `node_modules` folder could be found in any root directory.

* `babelrc`: Default `true`. When `false`, will ignore `.babelrc` files (except those referenced by the `extends` option).
* `cacheIdentifier`: Default is a string composed by the babel-core's version, the babel-loader's version, the contents of .babelrc file if it exists and the value of the environment variable `BABEL_ENV` with a fallback to the `NODE_ENV` environment variable. This can be set to a custom value to force cache busting if the identifier changes.

* `forceEnv`: Default will resolve BABEL_ENV then NODE_ENV. Allow you to override BABEL_ENV/NODE_ENV at the loader level. Useful for isomorphic applications with different babel configuration for client and server.
* `forceEnv`: Default will resolve BABEL_ENV then NODE_ENV. Allow you to override BABEL_ENV/NODE_ENV at the loader level. Useful for isomorphic applications with different babel configuration for client and server.

__Note:__ The `sourceMap` option is ignored, instead sourceMaps are automatically enabled when webpack is configured to use them (via the `devtool` config option).
__Note:__ The `sourceMap` option is ignored, instead sourceMaps are automatically enabled when webpack is configured to use them (via the `devtool` config option).

## Troubleshooting

### babel-loader is slow!

Make sure you are transforming as few files as possible. Because you are probably
matching `/\.js$/`, you might be transforming the `node_modules` folder or other unwanted
source.
Make sure you are transforming as few files as possible. Because you are probably
matching `/\.js$/`, you might be transforming the `node_modules` folder or other unwanted
source.

To exclude `node_modules`, see the `exclude` option in the `loaders` config as documented above.
To exclude `node_modules`, see the `exclude` option in the `loaders` config as documented above.

You can also speed up babel-loader by as much as 2x by using the `cacheDirectory` option.
This will cache transformations to the filesystem.
You can also speed up babel-loader by as much as 2x by using the `cacheDirectory` option.
This will cache transformations to the filesystem.

### babel is injecting helpers into each file and bloating my code!

babel uses very small helpers for common functions such as `_extend`. By default
this will be added to every file that requires it.
babel uses very small helpers for common functions such as `_extend`. By default
this will be added to every file that requires it.

You can instead require the babel runtime as a separate module to avoid the duplication.
You can instead require the babel runtime as a separate module to avoid the duplication.

The following configuration disables automatic per-file runtime injection in babel, instead
requiring `babel-plugin-transform-runtime` and making all helper references use it.
The following configuration disables automatic per-file runtime injection in babel, instead
requiring `babel-plugin-transform-runtime` and making all helper references use it.

See the [docs](http://babeljs.io/docs/plugins/transform-runtime/) for more information.
See the [docs](http://babeljs.io/docs/plugins/transform-runtime/) for more information.

**NOTE:** You must run `npm install babel-plugin-transform-runtime --save-dev` to include this in your project and `babel-runtime` itself as a dependency with `npm install babel-runtime --save`.
**NOTE:** You must run `npm install babel-plugin-transform-runtime --save-dev` to include this in your project and `babel-runtime` itself as a dependency with `npm install babel-runtime --save`.

```javascript
loaders: [
rules: [
// the 'transform-runtime' plugin tells babel to require the runtime
// instead of inlining it.
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['env'],
plugins: ['transform-runtime']
use: {
loader: 'babel-loader',
options: {
presets: ['env'],
plugins: ['transform-runtime']
}
}
}
]
Expand Down
8 changes: 6 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
environment:
nodejs_version: "6"
BABEL_ENV: "test"

install:
- ps: Install-Product node $env:nodejs_version
- npm install
- yarn

before_test:
- yarn run build

test_script:
- npm run test-ci
- yarn run test-only

build: off
65 changes: 47 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,55 @@
{
"name": "babel-loader",
"version": "6.4.1",
"version": "7.0.0-beta.1",
"description": "babel module loader for webpack",
"files": [
"lib"
],
"main": "lib/index.js",
"engines": {
"node": ">=4"
},
"dependencies": {
"find-cache-dir": "^0.1.1",
"loader-utils": "^0.2.16",
"mkdirp": "^0.5.1",
"object-assign": "^4.0.1"
"loader-utils": "^1.0.2",
"mkdirp": "^0.5.1"
},
"peerDependencies": {
"babel-core": "^6.0.0",
"webpack": "1 || 2 || ^2.1.0-beta || ^2.2.0-rc"
"babel-core": "6 || 7 || ^7.0.0-alpha || ^7.0.0-beta || ^7.0.0-rc",
"webpack": "2"
},
"devDependencies": {
"ava": "^0.17.0",
"ava": "^0.19.0",
"babel-cli": "^6.18.0",
"babel-core": "^6.0.0",
"babel-eslint": "^7.1.0",
"babel-plugin-istanbul": "^3.0.0",
"babel-plugin-istanbul": "^4.0.0",
"babel-plugin-react-intl": "^2.1.3",
"babel-preset-es2015": "^6.0.0",
"babel-preset-latest": "^6.16.0",
"babel-preset-env": "^1.2.0",
"babel-register": "^6.18.0",
"codecov": "^1.0.1",
"cross-env": "^2.0.0",
"cross-env": "^4.0.0",
"eslint": "^3.8.1",
"eslint-config-babel": "^6.0.0",
"eslint-plugin-flowtype": "^2.25.0",
"husky": "^0.13.2",
"lint-staged": "^3.3.1",
"nyc": "^10.0.0",
"prettier": "^1.2.2",
"react": "^15.1.0",
"react-intl": "^2.1.2",
"react-intl-webpack-plugin": "^0.0.3",
"rimraf": "^2.4.3",
"webpack": "^2.2.0-rc"
"webpack": "^2.2.0"
},
"scripts": {
"clean": "rimraf lib/",
"build": "babel src/ --out-dir lib/",
"coverage": "nyc report --reporter=json && codecov -f coverage/coverage-final.json",
"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",
"preversion": "npm test",
"prepublish": "npm run clean && npm run build",
"test": "npm run lint && cross-env BABEL_ENV=test npm run build && npm run test-only",
"test-ci": "cross-env BABEL_ENV=test npm run build && npm run test-only",
"precommit": "lint-staged",
"prepublish": "yarn run clean && yarn run build",
"preversion": "yarn run test",
"test": "yarn run lint && cross-env BABEL_ENV=test yarn run build && yarn run test-only",
"test-only": "nyc ava"
},
"repository": {
Expand All @@ -72,6 +75,10 @@
"include": [
"src/**/*.js"
],
"reporter": [
"text",
"json"
],
"require": [
"babel-register"
],
Expand All @@ -88,5 +95,27 @@
"src/**/*.js"
],
"babel": "inherit"
},
"lint-staged": {
"scripts/*.js": [
"prettier --trailing-comma es5 --write",
"git add"
],
"src/**/*.js": [
"prettier --trailing-comma all --write",
"git add"
],
"test/**/*.test.js": [
"prettier --trailing-comma all --write",
"git add"
],
"test/helpers/*.js": [
"prettier --trailing-comma all --write",
"git add"
],
"package.json": [
"node ./scripts/yarn-install.js",
"git add yarn.lock"
]
}
}
Loading

0 comments on commit 174cb10

Please sign in to comment.