我不能再做简化的webpack构建了,我也不明白为什么......
var React = require("react");
class App extends React.Component {
render() {
return <div>Hello World</div>;
}
}
React.render(<App />, document.body);
module.exports = {
entry: "./app.js",
output: {
filename: "bundle.js"
},
module: {
loaders: [
{
exclude: /(node_modules)/,
loader: 'babel'
}
]
}
};
$ webpack
ERROR in ./app.js
Module build failed: SyntaxError: /Users/alexbanks/Documents/code-play-2/eslint/app.js: Unexpected token (6:15)
4 |
5 | render() {
> 6 | return <div>Hello World</div>;
| ^
7 | }
8 |
9 | }
at Parser.pp.raise (/Users/alexbanks/Documents/code-play-2/eslint/node_modules/babylon/lib/parser/location.js:22:13)
at Parser.pp.unexpected (/Users/alexbanks/Documents/code-play-2/eslint/node_modules/babylon/lib/parser/util.js:91:8)
at Parser.pp.parseExprAtom (/Users/alexbanks/Documents/code-play-2/eslint/node_modules/babylon/lib/parser/expression.js:510:12)
at Parser.pp.parseExprSubscripts (/Users/alexbanks/Documents/code-play-2/eslint/node_modules/babylon/lib/parser/expression.js:265:19)
这是用于构建的东西。我尝试过使用react-dom,我有babel-loader,babel-core,并安装了反应。我已经尝试了包含React.createComponent的代码的几种变体......一切都给了我同样的错误。我的项目只有3个文件, app.js , webpack.config.js 和 index.html 。