webpack和babel出错(You may need an appropriate loader to handle this file type.)

使用webpack和babel编译ES6资源时出错:

You may need an appropriate loader to handle this file type. | import React from 'react'; | /* | import { render } from 'react-dom'

【webpack和babel出错(You may need an appropriate loader to handle this file type.)】下面是webpack配置:
var path = require('path'); var webpack = require('webpack'); module.exports = { entry: './index', output: { path: path.join(__dirname, 'dist'), filename: 'bundle.js', publicPath: '/dist/' }, module: { loaders: [ { test: /\.jsx?$/, loader: 'babel-loader', exclude: /node_modules/ } ] } }

解决办法
1、安装es2015预设:
npm install babel-preset-es2015

2、然后配置babel-loader:
{ test: /\.jsx?$/, loader: 'babel-loader', exclude: /node_modules/, query: { presets: ['es2015'] } }

    推荐阅读