如何让 browserify-rails 转译 es6 文件?
How do I get browserify-rails to transpile es6 files?
我刚刚使用 browserify-rails
和 Rails 4.2 创建了一个新项目。我的 package.json
看起来像这样:
{
"name": "neat-verify",
"dependencies": {
"browserify": "~> 10.2.4",
"browserify-incremental": "^3.0.1",
"es6ify": "^1.6.0",
"nuclear-js": "^1.1.1",
"react": "^0.13.3",
"reactify": "^1.1.1"
},
"browserify": {
"transform": [
[
"reactify",
"es6ify"
]
]
},
"license": "MIT",
"engines": {
"node": ">= 0.10"
}
}
一切都安装得很好,但是当我尝试用这个加载我非常简单的 es6 文件时:
module.exports = n => n * 11;
文件内容与上面完全相同,这不是我所期望的,因为这不是有效的 ES5。
我如何让它真正转译这个?
所以,在尝试了很多之后,我放弃了使用 browserify-rails
来执行转译,并决定使用 react-rails
,更简单,我转译 JSX 和 ES6 所需的只是包括这个配置:
config.react.jsx_transform_options = {
whitelist: [
"es6.arrowFunctions",
"es6.classes",
"react",
]
}
现在一个名为 foo.js.jsx
的文件包含:
var log = msg => console.log(msg);
class Hello extends React.Component {
render() {
return <div>Hello, {this.props.name}!</div>
}
}
正确转译并包含在 application.js
。
我刚刚使用 browserify-rails
和 Rails 4.2 创建了一个新项目。我的 package.json
看起来像这样:
{
"name": "neat-verify",
"dependencies": {
"browserify": "~> 10.2.4",
"browserify-incremental": "^3.0.1",
"es6ify": "^1.6.0",
"nuclear-js": "^1.1.1",
"react": "^0.13.3",
"reactify": "^1.1.1"
},
"browserify": {
"transform": [
[
"reactify",
"es6ify"
]
]
},
"license": "MIT",
"engines": {
"node": ">= 0.10"
}
}
一切都安装得很好,但是当我尝试用这个加载我非常简单的 es6 文件时:
module.exports = n => n * 11;
文件内容与上面完全相同,这不是我所期望的,因为这不是有效的 ES5。
我如何让它真正转译这个?
所以,在尝试了很多之后,我放弃了使用 browserify-rails
来执行转译,并决定使用 react-rails
,更简单,我转译 JSX 和 ES6 所需的只是包括这个配置:
config.react.jsx_transform_options = {
whitelist: [
"es6.arrowFunctions",
"es6.classes",
"react",
]
}
现在一个名为 foo.js.jsx
的文件包含:
var log = msg => console.log(msg);
class Hello extends React.Component {
render() {
return <div>Hello, {this.props.name}!</div>
}
}
正确转译并包含在 application.js
。