个性化阅读
专注于IT技术分析

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配置:

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']
    }
}
赞(0)
未经允许不得转载:srcmini » webpack和babel出错:You may need an appropriate loader to handle this file type.

评论 抢沙发

评论前必须登录!