Search code examples
reactjswebpackbabel-loader

plugins: [ new webpack.LoaderOptionsPlugin({ // test: /\.xxx$/, // may apply this only for some modules options: { modules: ... } }) ]


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"
  }
}

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration has an unknown property 'modules'. These properties are valid: object { mode?, amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, externals?, loader?, module?, name?, node?, output?, optimization?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? } For typos: please correct them. For loader options: webpack >= v2.0.0 no longer allows custom properties in configuration. Loaders should be updated to allow passing options via loader options in module.rules. Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader: plugins: [ new webpack.LoaderOptionsPlugin({ // test: /.xxx$/, // may apply this only for some modules options: { modules: ... } }) ]


Solution

  • 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
        }
    };