Skip to content

Commit

Permalink
Merge branch 'release/5.1.0'
Browse files Browse the repository at this point in the history
* release/5.1.0:
  Update README.md
  Update dependencies.
  Version bump
  Update README.md
  Update README.md
  Fix package.json version
  CS. Remove peerDependencies completely.
  Fix CS. Update README.md.
  Update test options to support babel 5
  Update dependencies.
  [WIP] Add test to output babel sourcemap
  Fix merge from develop.
  [WIP] Start work with sourcemaps.
  Closes #46. Add support for babel global options.
  Remove parsing of booleans.
  Update depedencies. Add files to .gitignore
  Add coverage to help with testing.
  [WIP] Add cache idenfier as option.
  [WIP] Move cache related functions to lib.
  Move cache related functions to own file.
  • Loading branch information
Couto committed May 15, 2015
2 parents 95d0b87 + 57566a7 commit 54d9e97
Show file tree
Hide file tree
Showing 20 changed files with 828 additions and 198 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
test/output
coverage
7 changes: 7 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"preset": "node-style-guide",
"fileExtensions": [ ".js", "jscs" ],
"excludeFiles": [
"node_modules/**"
]
}
17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Contributing

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

# Code Standards

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.

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.
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2014-2015 Luís Couto <hello@luiscouto.pt>

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
170 changes: 119 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,90 +1,158 @@
# babel-loader
> Babel is a compiler for writing next generation JavaScript.
> Turn ES6 code into vanilla ES5 with no runtime required using [babel](https://github.com/babel/babel);
This package allows the use babel with [webpack](https://github.com/webpack/webpack)

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

```
$ npm install --save-dev babel-loader
## Installation

```bash
npm install babel-loader --save-dev
```

## Usage
__Note:__ [npm](https://npmjs.com) will deprecate [peerDependencies](https://github.com/npm/npm/issues/6565) on the next major release, so required dependencies like babel-core and webpack will have to be installed manually.

```javascript
import Animal from 'babel!./Animal.js';
## Usage
Within your webpack configuration object, you'll need to add the babel-loader to the list of modules, like so:

class Person extends Animal {
constructor(arg='default') {
this.eat = 'Happy Meal';
}
```javascript
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel'
}
]
}
```

export default Person;
```
### Options

```javascript
var Person = require('babel!./Person.js').default;
new Person();
```
See the `babel` [options](http://babeljs.io/docs/usage/options/).

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

```javascript
```javascript
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'}
]
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel?optional[]=runtime&stage=0'
}
]
}
```
```

and then import normally:
or by using the query property:

```javascript
import Person from './Person.js';
```
```javascript
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
optional: ['runtime'],
stage: 0
}
}
]
}
```

This loader also supports the following loader-specific option:

* `cacheDirectory`: 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. A value of `true` will cause the loader to use the default OS temporary file directory.

* `cacheIdentifier`: When set, it will add the given identifier to the cached files. This can be used to force cache busting if the identifier changes. By default the identifier is made by using the babel-core's version and the babel-loader's version.


__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!
### 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. See the `exclude` option in the `loaders` config as documented above.
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.

#### babel is injecting helpers into each file and bloating my code!
See the `exclude` option in the `loaders` config as documented above.

babel uses very small helpers for common functions such as `_extend`. By default
this will be added to every file that requires it.
### babel is injecting helpers into each file and bloating my code!

You can instead require the babel runtime as a separate module to avoid the duplication.
babel uses very small helpers for common functions such as `_extend`. By default
this will be added to every file that requires it.

The following configuration disables automatic per-file runtime injection in babel, instead
requiring `babel-runtime` and making all helper references use it.
You can instead require the babel runtime as a separate module to avoid the duplication.

See the [docs](https://babeljs.io/docs/usage/runtime) for more information.
The following configuration disables automatic per-file runtime injection in babel, instead
requiring `babel-runtime` and making all helper references use it.

**NOTE:** You must run `npm install babel-runtime --save` to include this in your project.
See the [docs](https://babeljs.io/docs/usage/runtime) for more information.

**NOTE:** You must run `npm install babel-runtime --save` to include this in your project.

```javascript
loaders: [
// the optional 'runtime' transformer tells babel to require the runtime instead of inlining it.
{ test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader?optional=runtime' }
// the optional 'runtime' transformer tells babel to require the runtime
// instead of inlining it.
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader?optional[]=runtime'
}
]
```

## Options
#### custom polyfills (e.g. Promise library)

Since Babel includes a polyfill that includes a custom [regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) and [core.js](https://github.com/zloirock/core-js), the following usual shimming method using `webpack.ProvidePlugin` will not work:

See the `babel` [options](http://babeljs.io/docs/usage/options/)
```javascript
// ...
new webpack.ProvidePlugin({
'Promise': 'bluebird'
}),
// ...
```

This loader also supports the following loader-specific option:
The following approach will not work either:

* `cacheDirectory`: 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. A value of `true` will cause the loader to
use the default OS temporary file directory.
```javascript
require('babel-runtime/core-js/promise').default = require('bluebird');

var promise = new Promise;
```

which outputs to (using `runtime`):

```javascript
'use strict';

Note: The `sourceMap` option is ignored, instead sourceMaps are automatically enabled when webpack is configured to use them (via the `devtool` config option).
var _Promise = require('babel-runtime/core-js/promise')['default'];

## License
require('babel-runtime/core-js/promise')['default'] = require('bluebird');

var promise = new _Promise();
```

The previous `Promise` library is referenced and used before it is overridden.

One approach is to have a "bootstrap" step in your application that would first override the default globals before your application:

```javascript
// bootstrap.js

require('babel-runtime/core-js/promise').default = require('bluebird');

// ...

require('./app');
```

MIT © Luis Couto
## [License](http://couto.mit-license.org/)

0 comments on commit 54d9e97

Please sign in to comment.