Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does require('path'); means in Webpack.config.js?

I was configuring webpack configuration with my own instead of copy things and paste , I just need to understand each and every line in Webpack configuration file.

What is the use of the first line require('path') in webpack Configuration File.

const path = require('path');

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

https://webpack.github.io/docs/usage.html I am following the above link to getting things started

in the module.exports , path has been used but i did not get any idea in the usage of the path. Please let me know the usage. So i can start further.

like image 865
Gopinath Kaliappan Avatar asked Nov 23 '17 15:11

Gopinath Kaliappan


People also ask

How do I fix a webpack error?

To solve the "Cannot find module 'webpack'" error, make sure to install webpack globally by running the npm i -g webpack command and create a symbolic link from the globally-installed package to node_modules by running the npm link webpack command. Copied! Once you run the two commands, the error should be resolved.

What is __ Dirname in webpack?

__dirname returns the the directory name of the current module. Let's take a look at some code that uses __dirname . Without webpack. This is what the output of it looks like.

What is the location of webpack config js?

To answer your specific question, the webpack configuration is stored wherever your global node_modules are installed; on Windows this is typically %AppData%\Roaming\npm\node_modules\powerbi-visuals-tools\lib\webpack. config. js.


1 Answers

path is Node.js native utility module.

https://nodejs.org/api/path.html

require is Node.js global function that allows you to extract contents from module.exports object inside some file.

Unlike regular NPM modules, you don't need to install it because it's already inside Node.js

In your example you use path.resolve method which creates proper string representing path to your file.

Straight from docs:

The path.resolve() method resolves a sequence of paths or path segments into an absolute path.

https://nodejs.org/api/path.html#path_path_resolve_paths

like image 135
Kunok Avatar answered Oct 31 '22 10:10

Kunok