私はreact + webpack + hot moduleの代わりに簡単なボイラープレートを実行しようとしています。しかし、私は実際にbabel/jsxステップで立ち往生しており、助けが必要です。私はthis articleに従っています。webpack babel loaderがjsxをコンパイルできない
は現在、私は持っている:
webpack.config.js
:
module.exports = {
context: __dirname + "/app",
entry: "./app.js",
output: {
filename: "app.js",
path: __dirname + "/dist",
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loaders: ["babel-loader"],
}
],
},
}
app/app.js
:
import React from "react";
import Greeting from "./greeting";
React.render(
<Greeting name="World"/>,
document.body
);
とapp/greetings.js
を:
import React from "react";
export default React.createClass({
render: function() {
return (
<div className="greeting">
Hello, {this.props.name}!
</div>
);
},
});
package.json
でNDこの:
"devDependencies": {
"babel-core": "^6.18.0",
"babel-loader": "^6.2.7",
"webpack": "^1.13.3"
},
"dependencies": {
"react": "^15.3.2"
}
私はちょうどwebpack
コンソールで実行すると、チュートリアルが言うように、それは(下とバベル)WebPACKのを実行し、全体のアプリをバンドルし、それはないはずです - ではなく、それを次のエラースロー:
$ webpack
Hash: 9a56cc72acac2de6f40c
Version: webpack 1.13.3
Time: 543ms
+ 1 hidden modules
ERROR in ./app.js
Module build failed: SyntaxError: C:/Users/abc/Tests/webpack-react-hmr/app/app.js: Unexpected token (7:2)
5 |
6 | React.render(
> 7 | <Greeting name="World"/>,
| ^
8 | document.body
9 |);
10 |
を私はこのトピックに新たなんだので、私は問題が何であるかを知らない、しかし確実に、WebPACKのはJSXの構文を理解することはできません。たぶんthis part of the tutorialは、日付のうち間違っているかのどちらかである:
Fortunately the Babel loader supports transforming both ES2015 and JSX which means we can get away with using a single loader instead of requiring both the babel-loader and the jsx-loader.
We can install the babel loader with the following command:
npm install babel-loader --save-dev
私はWebPACKの/ JSX /バベルセットアップを修正するために何をすべき?
私は同じエラーが発生しており、これを並べ替えたことがあるのか不思議でした。私は同じチュートリアルに従っていません。 – Jtaks