前端技术之:使用webpack构建React程序配置方法
发表于:2024-11-24 作者:热门IT资讯网编辑
编辑最后更新 2024年11月24日,package.json中需要引入以下依赖:开发依赖:"@babel/core": "^7.1.2","@babel/preset-env": "^7.1.0","@babel/preset-reac
package.json中需要引入以下依赖:
开发依赖:
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.4",
运行时依赖:
"react": "^16.6.0",
"react-dom": "^16.6.0"
webpack.config.js中需要增加以下模块解析处理规则:
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
更详细的安装与配置方法请参考以下链接:
https://github.com/babel/babel-loader
https://babeljs.io/docs/en/next/babel-preset-react.html
https://www.npmjs.com/package/react
https://www.npmjs.com/package/react-dom