I cannot use Webpack in my project

Asked

Viewed 147 times

1

I’m learning React, and in the videos-classes I’m seeing, he has the global webpack installed:

npm i -g webpack

was successfully installed.

only in the video is created a directory dist archived bundle.js only that in my project these files do not appear. how do I generate them?

  1. I don’t have Node modules locally and I’m using Windows 10

whenever I try to run the webpack, it gives me that answer: inserir a descrição da imagem aqui

  • 1

    you need to have the webpack declared in your package.json and create a file called webpack.config.js where the webpack settings for your project will be.

1 answer

0

With the webpack installed, configure your webpack.config.js

    module.exports = {
 entry: './main.js',
 output: {
   filename: './bundle.js',
   path: path.resolve(__dirname,'dist')
 }
  };

put in your package.json a method to start:

"scripts": {
"start": "webpack-dev-server"
 }

run the script with npm start.

The logic itself is to take the content of the entry (its main file, which in this case is . /main.js) and turn it and dump it into output (which in this case, will be dist/Bundle.js).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.