Webpack ignores the webpack.config.js file

0

I'm following this tutorial to learn about Webpack ... The issue is that I configured the file as follows:

module.exports = {
    entry: "./app/entry",
    mode: "development",
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: "babel-loader"
                }
            }
        ]
    }
};

And I have my package.json as follows:

{
  "name": "pruebaWebpack",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack",
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.4",
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "webpack": "^4.4.1",
    "webpack-cli": "^2.0.13",
    "webpack-dev-server": "^3.1.1"
  },
  "dependencies": {
    "react": "^16.3.0",
    "react-dom": "^16.3.0"
  }
}

But apparently it is ignoring the configuration file because when I run npm run build it will look for the default files (entry = ./src and output = ./dist) and it does not recognize the%% attribute_of%:

  

[email protected] build / opt / lampp / htdocs / pruebaWebpack

     

webpack

     

Hash: 4a9c3de0f194dd38ac70 Version: webpack 4.4.1

     

Time: 234ms

     

Built at: 2018-4-1 15:53:00 Asset Size Chunks
  Chunk

     

Names main.js 564 bytes 0 [emitted] main Entrypoint main =   main.js [0] ./src/index.js 19 bytes {0} [built]

     

WARNING in configuration The 'mode' option has not been set, webpack   will fallback to 'production' for this value. Set 'mode' option to   'development' or 'production' to enable defaults for each environment.   You can also set it to 'none' to disable any default behavior. Learn   more: link

    
asked by Genarito 01.04.2018 в 20:56
source

1 answer

0

When you do

npm run build

the build line is executed within script in your package.json .

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack",
  },

According to the Webpack documentation , you should change your package.json a little

"scripts": {
  "dev": "webpack --mode development",
  "build": "webpack --mode production"
  "qa": "webpack --mode qa"
}

If you want to execute the develop mode command you must execute:

npm run dev
  

The way that node / npm uses different frameworks is based on the package.json that it is simply to decrease the command so that it is easier to learn and avoid the parameters that sometimes are cumbersome to learn them; in your example you can run npm run test and you will see "Error: no test specified"

    
answered by 02.04.2018 в 19:59