Webpack无法找到jsx文件

时间:2016-08-11 20:08:12

标签: javascript reactjs webpack jsx

我正在尝试捆绑和服务我在webpack dev服务器上的一个小应用程序。到目前为止它一直很好,但它似乎无法找到我的jsx文件。我的每个反应智能组件文件夹中都有一个索引,如下所示:

import Component from './component';
import container from './container';
import reducers from './reducers';

export default {
    Component,
    container,
    Container: container(),
    reducers
};

当我尝试运行捆绑包并说

时,Webpack抱怨
 client:47 ./client/ux-demo/index.js
 Module not found: Error: Cannot resolve 'file' or 'directory' ./component in /Users/me/projects/ux-demo/client/ux-demo

解析文件

唯一真正的区别是它是jsx文件,而不是js文件,但我有babel-loader。

这是我的webpack.config文件

var path = require('path');
var webpack = require('webpack');

module.exports = {
  devtool: 'eval',
  entry: [
    'webpack-dev-server/client?http://localhost:3000',
    'webpack/hot/only-dev-server',
    './client/app.jsx'
  ],
  output: {
    path: path.join(__dirname, 'client'),
    filename: 'bundle.js',
    publicPath: '/client/'
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin()
  ],
  module: {
    loaders: [{
      test: /\.js$/,
      loaders: ['react-hot', 'babel-loader'],
      include: path.join(__dirname, 'client')
    }, {
      test: /\.jsx$/,
      loaders: ['react-hot', 'babel-loader'],
      include: path.join(__dirname, 'client')
    }]
  }
};

不确定我在这里做错了什么,谢谢!

1 个答案:

答案 0 :(得分:2)

您需要告诉webpack解析.jsx文件

resolve:{
extensions:['.jsx']
}