关于webpack,babel和React发生了什么变化

时间:2015-11-23 19:54:41

标签: reactjs webpack babeljs

我不能再做简化的webpack构建了,我也不明白为什么......

app.js

var React = require("react");

class App extends React.Component {

    render() {
        return <div>Hello World</div>;
    }

}

React.render(<App />, document.body);

webpack.config.js

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

0 个答案:

没有答案