【问题标题】:Webpack unable to find jsx filesWebpack 找不到 jsx 文件
【发布时间】:2016-12-18 17:11:26
【问题描述】:

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

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')
    }]
  }
};

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

【问题讨论】:

  • 顺便说一句:为什么您有两个仅相差一个字符的加载程序?您可以使用匹配 /\.jsx?$/(同时匹配 .js.jsx)来组合它们。

标签: javascript reactjs webpack jsx


【解决方案1】:

你需要告诉 webpack 也解析 .jsx 文件

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

【讨论】:

    猜你喜欢
    • 2016-04-13
    • 2017-04-17
    • 2020-05-20
    • 2019-02-01
    • 1970-01-01
    • 2018-07-06
    • 2018-07-04
    • 2021-08-24
    • 1970-01-01
    相关资源
    最近更新 更多