Webpackは別の方法です。 Babelを使用してコードをトランジリックにすることができます。次に、webpack.config.js
ファイルの例を示します。
module.exports = {
// This code will be compiled
entry: "./app/App.js",
// Then output into this file
output: {
filename: "public/bundle.js"
},
// This will be what we do
module: {
loaders: [
{
test: /\.jsx?$/,
excluse: /(node_modules|bower_components)/,
loader: 'babel',
query: {
// These are the specific transformations we'll be using.
presets: ['react', 'es2015']
}
}
]
}
}
http://babeljs.io/docs/setup/#installation
インストールするには、いくつかのNPMパッケージがあります。次に、package.json
ファイルの例を示します。
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "public/index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.12.0",
"history": "^1.13.1",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-router": "^1.0.1" //for routing
},
"devDependencies": {
"babel-core": "^6.3.13",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"webpack": "^1.13.1"
}
}