下面是我的 webpack.config.js 代码
var webpack = require('webpack');
var path = require('path');
module.exports = {
// context: __dirname + "/app",
entry: [
'webpack-dev-server/client?http://0.0.0.0:8080',
'webpack/hot/only-dev-server',
'./src/main.jsx'],
output: {
path: "./build",
filename: "main.js"
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loaders: ['react-hot', 'babel'],
include: path.join(__dirname, 'build'),
query:
{
presets:['es2015', 'react']
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
}
]
}
}
这是我的 package.son 的脚本代码
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack",
"dev": "webpack-dev-server --devtool eval --progress --colors --hot --content-base build"
},
这是我的 main.js 代码
var React = require('react');
var ReactDOM = require('react-dom');
ReactDOM.render(
<h1>Hello World!</h1>,
document.getElementById('example')
);
当我输入 "npm run dev" 时,出现此错误
ERROR in ./src/main.jsx
Module parse failed: /Users/testaccount/Documents/React/test-react/src/main.jsx Line 6: Unexpected token <
You may need an appropriate loader to handle this file type.
|
| ReactDOM.render(
| <h1>Hello World!</h1>,
| document.getElementById('example')
| );
@ multi main
我去 localhost:8080 没有任何显示。有谁知道发生了什么?为什么我的 react-hot-loader 不起作用?