我将babel-core
替换为@babel/core
,而babel-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-loader
与babel-core
一起工作,但是如果我们想使用@babel/core
而不是babel-core
怎么办?
答案 0 :(得分:4)
AFAIK,您至少需要babel-loader@^8.0.0-beta
才能将babel 7+与webpack一起使用。 babel-loader
的稳定版本仍为版本7。请使用babel-loader@next
或指定要使用的加载程序的另一个beta版本。
这是注册表上的最新版本。 babel-loader 8.0.0-beta.6