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

时间:2018-08-23 05:15:56

标签: webpack babel

我将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-loaderbabel-core一起工作,但是如果我们想使用@babel/core而不是babel-core怎么办?

1 个答案:

答案 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