具有多个条目的 Webpack 无法解析 'file' 或 'directory'

Webpack with multiples entries cannot resolve 'file' or 'directory'

这是我第一次设置 webpack,到目前为止我还很困惑。我试图将我所有的 jsx 文件收集到它们各自的文件中,但 webpack 似乎认为它们不存在...

webpack --display-error-details

我收到如下错误:

ERROR in Entry module not found: Error: Cannot resolve 'file' or 'directory' ./static/js/base in /Users/Maude/Projects/School/entry
resolve file
  /Users/Maude/Projects/School/entry/static/js/base.js doesn't exist
  /Users/Maude/Projects/School/entry/static/js/base.jsx doesn't exist
  /Users/Maude/Projects/School/entry/static/js/base is not a file
resolve directory
  /Users/Maude/Projects/School/entry/static/js/base/package.json doesn't exist (directory description file)
  directory default file index
    resolve file index in /Users/Maude/Projects/School/entry/static/js/base
      /Users/Maude/Projects/School/entry/static/js/base/index doesn't exist
      /Users/Maude/Projects/School/entry/static/js/base/index.jsx doesn't exist
      /Users/Maude/Projects/School/entry/static/js/base/index.js doesn't exist

我的静态文件结构是这样的:

static
  |- js
      |- base
            |- base.jsx
      |- classes
            |- classes.jsx
            |- locations.jsx
      |- students
            |- students.jsx
            |- network.jsx
      |- teachers
            |- teachers.jsx
  |- less

最后是我的 webpack.config.js 文件:

module.exports = {
  entry: {
    base: './static/js/base',
    classes: './static/js/classes',
    students: './static/js/students',
    teachers: './static/js/teachers',
  },

  output: {
    path: './static/bundles',
    filename: '[name].js'
  },

  devServer: {
    inline: true,
    port: 3333
  },

  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: '/node_modules/',
        loader: 'babel',
        query: {
          presets: ['es2015', 'react']
        }
      }
    ]
  },

  resolve: {
    modulesDirectories: ['/node_modules/'],
    extensions: ['', '.js', '.jsx'],
  },

}

为什么我会收到像 ERROR in Entry module not found: Error: Cannot resolve 'file' or 'directory' 这样明明存在的错误?帮助欧比万!

还有我的package.json:

{
  "name": "--",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel": "^6.5.2",
    "babel-core": "^6.11.4",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-react": "^6.11.1",
    "bower": "^1.7.9",
    "gulp": "^3.9.1",
    "gulp-bower": "0.0.13",
    "gulp-changed": "^1.3.1",
    "gulp-concat": "^2.6.0",
    "gulp-cssmin": "^0.1.7",
    "gulp-html-replace": "^1.6.1",
    "gulp-less": "^3.1.0",
    "gulp-load-plugins": "^1.2.4",
    "gulp-plumber": "^1.1.0",
    "gulp-react": "^3.1.0",
    "gulp-rename": "^1.2.2",
    "gulp-replace": "^0.5.4",
    "gulp-shell": "^0.5.2",
    "gulp-uglify": "^1.5.4",
    "webpack": "^1.13.1",
    "webpack-dev-server": "^1.14.1"
  }
}

我认为你只需要一个入口文件,base.jsx,除非你的结构中有一个额外的索引文件。

webpack 将爬取导入并从中构建树结构

entry: './static/js/base.jsx'

编辑:对于单个入口点,您需要具有类似内容的文件:

React.render(<App />, document.getElementById('app')

根据你的 packaged.json,它看起来可能是 index.js,如果是,那么你输入 webpack.config.js

entry: './index.js'

然后 webpack 应该通过导入语句引入整个 React 应用程序以构建完整的捆绑文件。

顺便说一句。没有真正需要使用 .jsx 文件扩展名。只需使用 .js。这意味着您也不必担心 webpack

中的扩展字段

顺便说一句。你为什么混合使用 gulp 和 webpack?以前从没见过。也许最好选择 gulp/browserify 路线,或者坚持使用 webpack。