'未找到配置文件且未通过CLI选项配置条目'在webpack中

时间:2017-09-26 06:56:00

标签: reactjs webpack webpack-dev-server

我正在为自己的个人项目编写自己的webpack.config.js文件,我发现错误

No configuration file found and no entry configured via CLI option. When using the CLI you need to provide at least two arguments: entry and output. A configuration file could be named 'webpack.config.js' in the current directory. Use --help to display the CLI options.

我的webpack文件看起来像

const HTMLWebpackPlugin = require('html-webpack-plugin');
const HTMLWebpackPluginConfig = new HTMLWebpackPlugin({
  template: __dirname + '/index.html',
  filename: 'index.html',
  inject: 'body'
});

module.exports = {
  entry: './src/index.js',
  output: {
    path: __dirname,
    publicPath: '/',
    filename: 'bundle.js'
  },
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015', 'stage-1']
        }
      },
      {
        test: /\.css$/,
        loader: 'style-loader!css-loader'
      }
    ]
  },
  resolve: {
    extensions: ['', '.js', '.jsx']
  },
  plugins: [HTMLWebpackPluginConfig],
  devServer: {
    historyApiFallback: true,
    contentBase: './'
  }

};

正如您在我的webpack.config.js中看到的那样,有输入和输出但是webpack似乎没有因为某些原因识别它们而且我很长时间没有想到它。

我在webpack-dev-server文件中通过"devBuild": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js"使用package.json运行此网络包。

有没有人和我有过相似的经历并且知道如何使这项工作?

谢谢。

---------------------- EDIT ---------- 这是我的项目结构(抱歉不在开头发布)

root
|__client
|  |__React Folders
|  |__index.html
|  |__webpack.config.js
|
|__server
|  |__server.js
|
|__package.json
|__.babelrc
|__.gitignore

如果您需要别的东西,请告诉我。

1 个答案:

答案 0 :(得分:0)

将webpack.config.js移动到根目录

root
|__client
|  |__React Folders
|  |__index.html
|
|__server
|  |__server.js
|
|__package.json
|__.babelrc
|__.gitignore
|__webpack.config.js