Skip to content

Commit 174cb10

Browse files
committed
Merge branch '7.0'
# Conflicts: # README.md
2 parents 74ff2e6 + 2204871 commit 174cb10

21 files changed

+1769
-1386
lines changed

.babelrc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
22
"presets": [
3-
["latest", { "es2015": { "loose": true } }]
3+
["env", { "loose": true, "targets": { "node": 4 } }]
44
],
55
"env": {
66
"test": {
77
"plugins": ["istanbul"]
88
}
9-
},
10-
"comments": false
9+
}
1110
}

.eslintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
},
66
"extends": [
77
"eslint-config-babel"
8-
]
8+
],
9+
"rules": {
10+
"arrow-parens": "off"
11+
}
912
}

.travis.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ node_js:
55
- "6"
66
- "4"
77

8+
env:
9+
- JOB=test
10+
811
matrix:
12+
fast_finish: true
913
include:
1014
- node_js: "lts/*"
11-
env: WEBPACK_VERSION="1"
12-
- node_js: "lts/*"
13-
env: LINT=true
14-
- node_js: "0.10"
15-
env: WEBPACK_VERSION="1"
16-
- node_js: "0.12"
17-
env: WEBPACK_VERSION="1"
15+
env: JOB=lint
16+
1817
before_script:
19-
- 'if [ "$WEBPACK_VERSION" ]; then npm install webpack@$WEBPACK_VERSION; fi'
18+
- 'if [ "$JOB" = "test" ]; then BABEL_ENV=test yarn run build; fi'
19+
2020
script:
21-
- 'if [ -n "${LINT-}" ]; then npm run lint ; fi'
22-
- 'if [ -z "${LINT-}" ]; then npm run test-ci ; fi'
21+
- 'if [ "$JOB" = "test" ]; then yarn test-only; fi'
22+
- 'if [ "$JOB" = "lint" ]; then yarn run lint; fi'
2323
after_success:
24-
- npm run coverage
24+
- bash <(curl -s https://codecov.io/bash) -f coverage/coverage-final.json

README.md

Lines changed: 55 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,45 @@
1-
# babel-loader
21
[![NPM Status](https://img.shields.io/npm/v/babel-loader.svg?style=flat)](https://www.npmjs.com/package/babel-loader)
32
[![Build Status](https://travis-ci.org/babel/babel-loader.svg?branch=master)](https://travis-ci.org/babel/babel-loader)
43
[![Build Status](https://ci.appveyor.com/api/projects/status/vgtpr2i5bykgyuqo/branch/master?svg=true)](https://ci.appveyor.com/project/danez/babel-loader/branch/master)
54
[![codecov](https://codecov.io/gh/babel/babel-loader/branch/master/graph/badge.svg)](https://codecov.io/gh/babel/babel-loader)
6-
> Babel is a compiler for writing next generation JavaScript.
75

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

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

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

14-
```bash
15-
npm install babel-loader babel-core babel-preset-env webpack --save-dev
16-
```
20+
<h2 align="center">Install</h2>
1721

18-
or
22+
> webpack 1.x | babel-loader <= 6.x
23+
>
24+
> webpack 2.x | babel-loader >= 7.x (recommended) (^6.2.10 will also work, but with deprecation warnings)
1925
2026
```bash
2127
yarn add babel-loader babel-core babel-preset-env webpack --dev
2228
```
2329

24-
__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`.
30+
We recommend using yarn, but you can also still use npm:
2531

26-
__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).
32+
```bash
33+
npm install --save-dev babel-loader babel-core babel-preset-env webpack
34+
```
2735

28-
## Usage
36+
<h2 align="center">Usage</h2>
2937

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

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

34-
```javascript
42+
```javascript
3543
module: {
3644
rules: [
3745
{
@@ -46,29 +54,16 @@ module: {
4654
}
4755
]
4856
}
49-
```
57+
```
5058

5159
### Options
5260

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

55-
You can pass options to the loader by writing them as a [query string](https://github.com/webpack/loader-utils):
56-
57-
```javascript
58-
module: {
59-
rules: [
60-
{
61-
test: /\.js$/,
62-
exclude: /(node_modules|bower_components)/,
63-
loader: 'babel-loader?presets[]=env'
64-
}
65-
]
66-
}
67-
```
6863

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

71-
```javascript
66+
```javascript
7267
module: {
7368
rules: [
7469
{
@@ -77,83 +72,65 @@ module: {
7772
use: {
7873
loader: 'babel-loader',
7974
options: {
80-
presets: ['env']
75+
presets: ['env'],
76+
plugins: [require('babel-plugin-transform-object-rest-spread')]
8177
}
8278
}
8379
}
8480
]
8581
}
86-
```
87-
88-
or by using global options:
89-
90-
> Be aware that this only works in webpack 1 and not in version 2.
91-
92-
```javascript
93-
module: {
94-
loaders: [
95-
{
96-
test: /\.js$/,
97-
exclude: /(node_modules|bower_components)/,
98-
loader: 'babel-loader'
99-
}
100-
]
101-
},
102-
babel: {
103-
presets: ['es2015']
104-
}
105-
```
106-
107-
This loader also supports the following loader-specific option:
82+
```
10883

109-
* `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.
84+
This loader also supports the following loader-specific option:
11085

111-
* `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.
86+
* `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.
11287

113-
* `babelrc`: Default `true`. When `false`, will ignore `.babelrc` files (except those referenced by the `extends` option).
88+
* `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.
11489

115-
* `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.
90+
* `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.
11691

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

11994
## Troubleshooting
12095

12196
### babel-loader is slow!
12297

123-
Make sure you are transforming as few files as possible. Because you are probably
124-
matching `/\.js$/`, you might be transforming the `node_modules` folder or other unwanted
125-
source.
98+
Make sure you are transforming as few files as possible. Because you are probably
99+
matching `/\.js$/`, you might be transforming the `node_modules` folder or other unwanted
100+
source.
126101

127-
To exclude `node_modules`, see the `exclude` option in the `loaders` config as documented above.
102+
To exclude `node_modules`, see the `exclude` option in the `loaders` config as documented above.
128103

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

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

134-
babel uses very small helpers for common functions such as `_extend`. By default
135-
this will be added to every file that requires it.
109+
babel uses very small helpers for common functions such as `_extend`. By default
110+
this will be added to every file that requires it.
136111

137-
You can instead require the babel runtime as a separate module to avoid the duplication.
112+
You can instead require the babel runtime as a separate module to avoid the duplication.
138113

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

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

144-
**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`.
119+
**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`.
145120

146121
```javascript
147-
loaders: [
122+
rules: [
148123
// the 'transform-runtime' plugin tells babel to require the runtime
149124
// instead of inlining it.
150125
{
151126
test: /\.js$/,
152127
exclude: /(node_modules|bower_components)/,
153-
loader: 'babel-loader',
154-
query: {
155-
presets: ['env'],
156-
plugins: ['transform-runtime']
128+
use: {
129+
loader: 'babel-loader',
130+
options: {
131+
presets: ['env'],
132+
plugins: ['transform-runtime']
133+
}
157134
}
158135
}
159136
]

appveyor.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
environment:
22
nodejs_version: "6"
3+
BABEL_ENV: "test"
34

45
install:
56
- ps: Install-Product node $env:nodejs_version
6-
- npm install
7+
- yarn
8+
9+
before_test:
10+
- yarn run build
711

812
test_script:
9-
- npm run test-ci
13+
- yarn run test-only
1014

1115
build: off

package.json

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,55 @@
11
{
22
"name": "babel-loader",
3-
"version": "6.4.1",
3+
"version": "7.0.0-beta.1",
44
"description": "babel module loader for webpack",
55
"files": [
66
"lib"
77
],
88
"main": "lib/index.js",
9+
"engines": {
10+
"node": ">=4"
11+
},
912
"dependencies": {
1013
"find-cache-dir": "^0.1.1",
11-
"loader-utils": "^0.2.16",
12-
"mkdirp": "^0.5.1",
13-
"object-assign": "^4.0.1"
14+
"loader-utils": "^1.0.2",
15+
"mkdirp": "^0.5.1"
1416
},
1517
"peerDependencies": {
16-
"babel-core": "^6.0.0",
17-
"webpack": "1 || 2 || ^2.1.0-beta || ^2.2.0-rc"
18+
"babel-core": "6 || 7 || ^7.0.0-alpha || ^7.0.0-beta || ^7.0.0-rc",
19+
"webpack": "2"
1820
},
1921
"devDependencies": {
20-
"ava": "^0.17.0",
22+
"ava": "^0.19.0",
2123
"babel-cli": "^6.18.0",
2224
"babel-core": "^6.0.0",
2325
"babel-eslint": "^7.1.0",
24-
"babel-plugin-istanbul": "^3.0.0",
26+
"babel-plugin-istanbul": "^4.0.0",
2527
"babel-plugin-react-intl": "^2.1.3",
26-
"babel-preset-es2015": "^6.0.0",
27-
"babel-preset-latest": "^6.16.0",
28+
"babel-preset-env": "^1.2.0",
2829
"babel-register": "^6.18.0",
29-
"codecov": "^1.0.1",
30-
"cross-env": "^2.0.0",
30+
"cross-env": "^4.0.0",
3131
"eslint": "^3.8.1",
3232
"eslint-config-babel": "^6.0.0",
3333
"eslint-plugin-flowtype": "^2.25.0",
34+
"husky": "^0.13.2",
35+
"lint-staged": "^3.3.1",
3436
"nyc": "^10.0.0",
37+
"prettier": "^1.2.2",
3538
"react": "^15.1.0",
3639
"react-intl": "^2.1.2",
3740
"react-intl-webpack-plugin": "^0.0.3",
3841
"rimraf": "^2.4.3",
39-
"webpack": "^2.2.0-rc"
42+
"webpack": "^2.2.0"
4043
},
4144
"scripts": {
4245
"clean": "rimraf lib/",
4346
"build": "babel src/ --out-dir lib/",
44-
"coverage": "nyc report --reporter=json && codecov -f coverage/coverage-final.json",
47+
"format": "prettier --write --trailing-comma all \"src/**/*.js\" \"test/*.test.js\" \"test/helpers/*.js\" && prettier --write --trailing-comma es5 \"scripts/*.js\"",
4548
"lint": "eslint src test",
46-
"preversion": "npm test",
47-
"prepublish": "npm run clean && npm run build",
48-
"test": "npm run lint && cross-env BABEL_ENV=test npm run build && npm run test-only",
49-
"test-ci": "cross-env BABEL_ENV=test npm run build && npm run test-only",
49+
"precommit": "lint-staged",
50+
"prepublish": "yarn run clean && yarn run build",
51+
"preversion": "yarn run test",
52+
"test": "yarn run lint && cross-env BABEL_ENV=test yarn run build && yarn run test-only",
5053
"test-only": "nyc ava"
5154
},
5255
"repository": {
@@ -72,6 +75,10 @@
7275
"include": [
7376
"src/**/*.js"
7477
],
78+
"reporter": [
79+
"text",
80+
"json"
81+
],
7582
"require": [
7683
"babel-register"
7784
],
@@ -88,5 +95,27 @@
8895
"src/**/*.js"
8996
],
9097
"babel": "inherit"
98+
},
99+
"lint-staged": {
100+
"scripts/*.js": [
101+
"prettier --trailing-comma es5 --write",
102+
"git add"
103+
],
104+
"src/**/*.js": [
105+
"prettier --trailing-comma all --write",
106+
"git add"
107+
],
108+
"test/**/*.test.js": [
109+
"prettier --trailing-comma all --write",
110+
"git add"
111+
],
112+
"test/helpers/*.js": [
113+
"prettier --trailing-comma all --write",
114+
"git add"
115+
],
116+
"package.json": [
117+
"node ./scripts/yarn-install.js",
118+
"git add yarn.lock"
119+
]
91120
}
92121
}

0 commit comments

Comments
 (0)