gpt4 book ai didi

webpack - Babel-loader 需要 babel-core 而不是 @babel/core

转载 作者:行者123 更新时间:2023-12-02 07:18:34 29 4
gpt4 key购买 nike

我用 @babel/core 替换了 babel-corebabel-loader 期望 babel-core:

{
"name": "myproject-ui",
"version": "1.0.0",
"description": "User interface for myproject",
"main": "index.js",
"scripts": {
"start": "npx webpack-dev-server",
"build": "npx webpack",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Hello",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.0.0-rc.2",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-rc.2",
"@babel/preset-env": "^7.0.0-rc.2",
"@babel/preset-react": "^7.0.0-rc.2",
"babel-loader": "^7.1.5",
"webpack": "^4.16.5",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.5"
},
"babel": {
"presets": [
"env",
"react",
"@babel/plugin-proposal-object-rest-spread"
]
},
"dependencies": {
"axios": "^0.18.0",
"history": "^4.7.2",
"react": "^16.4.2",
"react-dom": "^16.4.2",
"react-router-dom": "^4.3.1"
}
}

这是我的 webpack 配置文件:

module.exports = {
entry: './src/index.js',
output: {
path: __dirname,
publicPath: '/',
filename: 'bundle.js'
},
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}]
},
mode: 'development',
devServer: {
historyApiFallback: true,
contentBase: './'
}
};

我知道 babel-loaderbabel-core 一起工作,但是如果我们想使用 @babel/core 而不是 babel-核心?

最佳答案

据我所知,您至少需要 babel-loader@^8.0.0-beta 才能将 babel 7+ 与 webpack 一起使用。 babel-loader 的稳定版本仍然是版本 7。使用 babel-loader@next 或指定要使用的加载程序的另一个 beta 版本。

这是注册表中的最新版本。 babel-loader 8.0.0-beta.6

关于webpack - Babel-loader 需要 babel-core 而不是 @babel/core,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51978775/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com