升级Laravel Mix以使用Babel 7

时间:2018-12-19 18:40:17

标签: laravel webpack babel

我需要更新Laravel组合才能使用Babel 7。

我将依赖关系更新为使用应支持Babel 7的Laravel Mix 4.0.7。

import numpy as np
from scipy import interpolate

import matplotlib.pyplot as plt


y = np.array([150, 0.0, 0.0, 0.0, 0.0, 144.0, 144.0, 145.0, 145.0, 144.0, 143.0, 143.0, 0.0, 0.0, 148])
x = np.arange(len(y))
x_ = np.linspace(0, 14, 100)
mask = (y != 0)

p = interpolate.interp1d(x, y, kind='cubic')
p_masked = interpolate.interp1d(x[mask], y[mask], kind='cubic')

plt.plot(x, y, 'x-', label='Input')
plt.plot(x_, p(x_), label='Interpolated')
plt.plot(x_, p_masked(x_), label='Interpolated (ignoring zeros)')
plt.legend()
plt.savefig('/tmp/cubic_interpolation.png', dpi=300)
plt.show()

在我的.babelrc文件中,我有:

  "devDependencies": {
    "@babel/core": "^7.2.2",
    "@babel/plugin-proposal-class-properties": "^7.2.1",
    "@babel/preset-env": "^7.2.0",
    "@babel/preset-react": "^7.0.0",
    "axios": "^0.15.3",
    "babel-loader": "^7.1.5",
    "bootstrap": "4.1.3",
    "browser-sync": "^2.26.3",
    "browser-sync-webpack-plugin": "^2.0.1",
    "jquery": "^3.1.1",
    "laravel-mix": "^4.0.7",
    "less": "^3.9.0",
    "less-loader": "^4.1.0",
    "lodash": "^4.17.10",
    "react-color": "^2.14.1",
    "resolve-url-loader": "^2.3.1",
    "sass": "^1.15.2",
    "sass-loader": "^7.1.0",
    "styled-components": "^4.0.3",
    "vue": "^2.5.13"
  }

在我的webpack.mix.js中,我有:

{
  "loader": "babel-loader",
  "presets": ["@babel/preset-env", "@babel/preset-react"],
  "plugins": [
    "@babel/plugin-proposal-object-rest-spread",
    "@babel/plugin-proposal-class-properties",
    "@babel/plugin-transform-react-jsx"
  ]
}

问题是当我运行npm run watch时出现以下错误:

模块构建失败(来自./node_modules/babel-loader/lib/index.js): 错误:找不到模块“ babel-core”

显然,Laravel Mix正在尝试使用babel-core而不是@ babel / core。

关于如何解决此问题的任何想法?

1 个答案:

答案 0 :(得分:2)

我相信您需要将babel-loader升级到8.x。

如果您阅读https://www.npmjs.com/package/babel-loader上的文档

  

此自述文件适用于babel-loader v8 + Babel v7

     

使用Babel v6检查7.x分支中的文档

因此,babel-loader 8.x与@ babel-core 7一起使用。babel-loader 7.x与babel-core 6.x一起使用