Skip to content

Commit eee9e9a

Browse files
committed
feat: add webpack explanations
1 parent a5e162d commit eee9e9a

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

advanced/modules_webpack.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// 📌 JavaScript Intermediate - Modules and Webpack
2+
3+
// Welcome to the seventh section of the JavaScript Intermediate tutorial!
4+
// Here, you'll learn how to use JavaScript modules and bundle them with Webpack.
5+
6+
// Using ES6 Modules
7+
// Exporting a function (file: math.js)
8+
export function add(a, b) {
9+
return a + b;
10+
}
11+
12+
// Importing a function (file: main.js)
13+
import { add } from "./math.js";
14+
console.log("Sum:", add(5, 3));
15+
16+
// Default Export
17+
// Exporting (file: user.js)
18+
export default class User {
19+
constructor(name) {
20+
this.name = name;
21+
}
22+
greet() {
23+
console.log(`Hello, ${this.name}!`);
24+
}
25+
}
26+
27+
// Importing (file: main.js)
28+
import User from "./user.js";
29+
const user = new User("Alice");
30+
user.greet();
31+
32+
// Webpack Overview
33+
// Webpack is a module bundler that helps manage dependencies and optimize code.
34+
// Steps to set up Webpack:
35+
// 1. Install Webpack and Webpack CLI:
36+
// npm install webpack webpack-cli --save-dev
37+
// 2. Create a webpack.config.js file
38+
// 3. Set entry, output, and loaders in the config file
39+
// 4. Run Webpack to bundle your JavaScript files:
40+
// npx webpack
41+
42+
// 💡 Practice using ES6 modules and setting up Webpack in a project!

0 commit comments

Comments
 (0)