Webpack运行构建&看ERROR

时间:2017-11-22 00:41:17

标签: npm webpack build command watch

我正在阅读媒体上的story,试图学习如何使用npm和webpack以及现代JavaScript。在安装webpack之前,每件事都很棒。 我尝试运行此命令npm run buildnpm run watch这些脚本存在于package.json文件中



{
  "name": "ebdae",
  "version": "1.0.0",
  "description": "nodescription",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack --progress -p",
    "watch": "webpack --progress --watch"
  },
  "repository": {
    "type": "git",
    "url": "ebdae"
  },
  "author": "elhakim",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-env": "^1.6.1",
    "webpack": "^3.8.1"
  },
  "dependencies": {}
}




但是这会在命令行No configuration file found and no output filename configured via CLI option. A configuration file could be named 'webpack.config.js' in the current directory.

上显示此错误

但配置文件通常存在于.bin文件夹中,它包含以下代码:



module.exports = {
  entry: '../../assets/js/index.js',
  output: {
    filename: '../../assets/js/bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['env']
          }
        }
      }
    ]
  }
};




和树结构如下:

| .git
| assets
    | js
        | index.js
        | bundle.js
| node_modules
    | .bin
        | ...
        | webpack.config.js
| package-lock.json
| package.json

1 个答案:

答案 0 :(得分:2)

您的脚本中未提供任何webpack配置文件。

应该是这样的

"build": "webpack --progress -p --config /node_modules/.bin/webpack.config.js"