【发布时间】:2023-03-27 15:23:01
【问题描述】:
我已经按照这个简单的教程 (http://jslog.com/2014/10/02/react-with-webpack-part-1/) 开始使用 React 和 webpack,但是在尝试使用更新的语法时遇到了问题。即使用 ReactDom 调用 render 而不是已弃用的 'React.renderComponent'。
我已经跑了:
npm install --save react-dom
并添加
var ReactDom = require('react-dom')
到 index.jsx 文件并添加
'react-dom': 'ReactDom'
到 webpack.config.js 中的“外部”列表。 (我不确定这是否有必要。)
但是我得到了 javascript 错误 ReactDom is not defined。
webpack.config.js:
module.exports = {
entry: './index.jsx',
output: {
filename: 'bundle.js', //this is the default name, so you can skip it
//at this directory our bundle file will be available
//make sure port 8090 is used when launching webpack-dev-server
publicPath: 'http://localhost:8090/assets'
},
module: {
loaders: [
{
//tell webpack to use jsx-loader for all *.jsx files
test: /\.jsx$/,
loader: 'jsx-loader?insertPragma=React.DOM&harmony'
}
]
},
externals: {
//don't bundle the 'react' npm package with our bundle.js
//but get it from a global 'React' variable
'react': 'React'
},
resolve: {
extensions: ['', '.js', '.jsx']
}
}
【问题讨论】:
-
Mike 请尝试选择一个问题标题来描述您的问题,并且其他人可以使用 google 或 bing 找到类似问题的问题
-
一切看起来都很好。应该管用。您不需要外部设备。您能否也添加您的 webpack 配置?
标签: javascript reactjs webpack