WEBPACK错误:当我执行npm start时,出现“无效的参数数量”错误

时间:2018-09-04 04:09:30

标签: webpack webpack-dev-server npm-start webpack.config.js

是webpack的新手。

我显然做错了或做错了。但是那不是什么。

在我的package.json中,scripts下,我定义了自己的脚本,这些脚本可以为我的项目运行。

build中,我只是将内容从src复制到dist。

下面是webpack.config.jspackage.json的代码

操作系统:Windows 10

package.json

{
  "name": "react-project",
  "version": "1.0.0",
  "description": "react-project",
  "main": "index.js",
  "scripts": {
    "start": "npm run build",
    "build": "webpack -d && xcopy src/index.html dist/index.html && webpack-dev-server --content-base src/ --hot",
    "build:prod": "webpack -p && xcopy src/index.html dist/index.html"
  },
  "keywords": [
    "react"
  ],
  "author": "Nauman Tanwir",
  "license": "ISC",
  "dependencies": {
    "react": "^16.4.2",
    "react-dom": "^16.4.2"
  },
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",
    "webpack": "^4.17.2",
    "webpack-cli": "^3.1.0",
    "webpack-dev-server": "^3.1.7"
  }
}

webpack.config.js

var path = require("path");

var DIST_DIR = path.resolve(__dirname, "dist");
var SRC_DIR = path.resolve(__dirname, "src");

var config = {
    entry: SRC_DIR + "/app/index.js",
    output: {
        path: DIST_DIR + "/app",
        filename: "bundle.js",
        publicPath: "/app/"
    },
    module: {
        rules: [{
            test: /\.js?/,
            include: SRC_DIR,
            loader: "babel-loader",
            query: {
                presets: ["react", "es2015", "stage-2"]
            }
        }]
    }
};

module.exports = config;

enter image description here

0 个答案:

没有答案