-1
var webpack = require("webpack");
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/"
    },

    modules: {
        loaders: [
            {
                test: /\.js?/,
                include: SRC_DIR,
                loader: "babel-loader",
                query: {
                    presets: [["react","es2015","stage-2"]]

                } 

            }


        ]
    }
};

module.exports = config;


{
  "name": "react-app",
  "version": "1.0.0",
  "description": "my first react app",
  "main": "index.js",
  "scripts": {
    "start": "npm run build",
    "build": "webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot",
    "build:prod": "webpack -p && cp src/index.html dist/index.html"
  },
  "keywords": [
    "\"React\""
  ],
  "author": "Dnyanesh",
  "license": "ISC",
  "dependencies": {
    "@babel/core": "^7.0.0-beta.40",
    "@babel/preset-env": "^7.0.0-beta.40",
    "react": "^16.2.0",
    "react-dom": "^16.2.0"
  },
  "devDependencies": {
    "babel-loader": "^8.0.0-beta.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",
    "webpack": "^4.1.0",
    "webpack-cli": "^2.0.10",
    "webpack-dev-server": "^3.1.0"
  }
}

配置对象无效。Webpack 已使用与 API 模式不匹配的配置对象进行初始化。- 配置具有未知属性“模块”。这些属性是有效的:object { mode?, amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, externals?, loader?, module?, name?, node?, output ?,优化?,并行?,性能?,插件?,配置文件?,recordsInputPath?,recordsOutputPath?,recordsPath?,resolve?,resolveLoader?,stats?,target?,watch?,watchOptions?} 对于错别字:请更正。对于加载器选项:webpack >= v2.0.0 不再允许配置中的自定义属性。应该更新加载器以允许通过 module.rules 中的加载器选项传递选项。

4

2 回答 2

0

由于错误清楚地表明您的配置应包含modulenot modulescheck here

于 2018-03-05T19:18:16.563 回答
0
const webpack = require('webpack');
const path = require('path');

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

module.exports = {
    entry: SRC_DIR + "/app/index.js",
    output: {
        path: DIST_DIR + "/app",
        filename: "bundle.js",
        publicPath: "/app/"
    },
    module: {
        rules: [
            {
                test: /\.js?$/,
                include: SRC_DIR,
                loaders: "babel-loader",
                options: {
                    presets: ["react", "es2016", "stage-2"]

                }
            }


        ]
    },
    performance: {
        hints: process.env.NODE_ENV === 'production' ? "warning" : false
    }
};
于 2018-03-06T12:47:34.333 回答