Couldn't find preset "es2015" relative to directory

在引入element-ui引发的问题,解决如下:

  1.npm install babel-preset-es2015 --save-dev

  2.修改.babelrc 

    

{
  "presets": [
    ["es2015", { "modules": false }],
    ["env", {
      "modules": false,
      "targets": {
        "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
      }
    }],
    "stage-2"
  ],
  "plugins": [
    "transform-vue-jsx",
    "transform-runtime",
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ]
  ],
  "env": {
    "test": {
      "presets": ["env", "stage-2"]
    }
  }
}

  3.在webpack.base.conf.js文件中加入如下代码:

  

loaders: [
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel',
        query: {
          presets: ['es2015']
        }
      }
    ]

Couldn't find preset "es2015" relative to directory

 

 

上一篇:[javascript] 主流浏览器对ES6的支持情况


下一篇:babel的使用