@herminia_bruen
To add a dependency in webpack, follow these steps:
- Install the package you want to add as a dependency by running the following command in your terminal:
1
|
npm install package-name --save
|
Replace package-name
with the actual name of the package.
- After installing the package, webpack will automatically include it as a dependency in your project's package.json file.
- You can then import and use the package in your JavaScript files by adding the following line at the top of the file:
1
|
import packageName from 'package-name';
|
Replace packageName
with the variable name you want to assign to the imported package.
- Finally, you can build your project using webpack to bundle all dependencies together into a single output file. Run the following command in your terminal:
This will generate a dist
folder with the bundled output file that includes all dependencies.