Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
switch from babel-preset-es2015 to babel-preset-env (#115)
Browse files Browse the repository at this point in the history
* switch from babel-preset-es2015 to babel-preset-env addresses #112 and #113

* minor letter casing the way it is preffered on Google Analytics Website

* Run prettier after merge

* removing contributors section in favor of separate PR

* chnage babel config on README to single quote
  • Loading branch information
svenkatreddy authored and zpao committed Oct 31, 2017
1 parent eb465db commit a42989c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Next
* switch from babel-preset-es2015 to babel-preset-env

# v0.10.4 (2017-10-13)

* Fixed bug preventing the use of arrays for the Express views setting
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ option | values | default
`doctype` | any string that can be used as [a doctype](http://en.wikipedia.org/wiki/Document_type_declaration), this will be prepended to your document | `"<!DOCTYPE html>"`
`beautify` | `true`: beautify markup before outputting (note, this can affect rendering due to additional whitespace) | `false`
`transformViews` | `true`: use `babel` to apply JSX, ESNext transforms to views.<br>**Note:** if already using `babel-register` in your project, you should set this to `false` | `true`
`babel` | any object containing valid Babel options<br>**Note:** does not merge with defaults | `{presets: ['react', 'es2015']}`
`babel` | any object containing valid Babel options<br>**Note:** does not merge with defaults | `{presets: ['react', [ 'env', {'targets': {'node': 'current'}}]]}`

The defaults are sane, but just in case you want to change something, here's how it would look:

Expand All @@ -46,7 +46,7 @@ app.engine('jsx', require('express-react-views').createEngine(options));

### Views

Under the hood, [Babel][babel] is used to compile your views into ES5 friendly code, using the [react][babel-preset-react] and [es2015][babel-preset-es2015] presets by default. Only the files in your `views` directory (i.e. `app.set('views', __dirname + '/views')`) will be compiled.
Under the hood, [Babel][babel] is used to compile your views to code compatible with your current node version, using the [react][babel-preset-react] and [env][babel-preset-env] presets by default. Only the files in your `views` directory (i.e. `app.set('views', __dirname + '/views')`) will be compiled.

Your views should be node modules that export a React component. Let's assume you have this file in `views/index.jsx`:

Expand Down Expand Up @@ -149,18 +149,19 @@ All "locals" are exposed to your view in `this.props`. These should work identic

```js
<script dangerouslySetInnerHTML={{__html: `
// google analytics
// Google Analytics
// is a common use
`}} />
```

* It's not possible to specify a doctype in JSX. You can override the default HTML5 doctype in the options.


[express]: http://expressjs.com/
[react]: http://facebook.github.io/react/
[jade]: http://jade-lang.com/
[ejs]: http://embeddedjs.com/
[hbs]: https://github.com/barc/express-hbs
[babel]: https://babeljs.io/
[babel-preset-react]: https://babeljs.io/docs/plugins/preset-react/
[babel-preset-es2015]: https://babeljs.io/docs/plugins/preset-es2015/
[babel-preset-env]: https://babeljs.io/docs/plugins/preset-env/
6 changes: 6 additions & 0 deletions examples/dynamic/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"react",
"env"
]
}
4 changes: 2 additions & 2 deletions examples/dynamic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"private": true,
"scripts": {
"start":
"browserify -t [ babelify --presets [ es2015 react ] --standalone main views/main.js -o public/main.js ] && node app.js"
"browserify -t babelify views/main.js --standalone main -o public/main.js && node app.js"
},
"dependencies": {
"babel-preset-es2015": "^6.24.1",
"babel-preset-env": "^1.6.0",
"babel-preset-react": "^6.24.1",
"babelify": "^7.3.0",
"browserify": "^14.3.0",
Expand Down
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ var DEFAULT_OPTIONS = {
beautify: false,
transformViews: true,
babel: {
presets: ['react', 'es2015'],
presets: [
'react',
[
'env',
{
targets: {
node: 'current',
},
},
],
],
},
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"react-dom": "^0.14.0 || ^15.0.0 || ^16.0.0"
},
"dependencies": {
"babel-preset-es2015": "^6.24.1",
"babel-preset-env": "^1.6.0",
"babel-preset-react": "^6.24.1",
"babel-register": "^6.26.0",
"js-beautify": "^1.7.3",
Expand Down

0 comments on commit a42989c

Please sign in to comment.