Webpack 기초 복습
번들링, 로더, 플러그인을 비롯한 Webpack의 핵심 기능을 복습합니다.
Webpack 기초 복습은(는) CoddyKit의 무료 Micro Frontends Architecture with Module Federation 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Micro Frontends Architecture with Module Federation 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Micro Frontends Architecture with Module Federation 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Welcome to Webpack!
Hello! Today, we'll refresh our knowledge of Webpack, a powerful tool for modern web development. It's often called a static module bundler.
Think of it as a smart assistant that takes all your project files – JavaScript, CSS, images – and bundles them into a few optimized files for the browser.
Why Do We Bundle?
In web development, we often break our code into many small, manageable files (modules). While great for organization, this can lead to a problem:
- Many HTTP Requests: Each file needs to be downloaded separately by the browser.
- Slower Load Times: Too many requests can slow down your website.
Bundling solves this by combining these files, reducing requests and improving performance!
Entry Point: The Starting Line
Webpack needs to know where to start. This is called the entry point. It's typically your main application file, like index.js.
From this entry point, Webpack builds a dependency graph, understanding which files depend on each other through import or require() statements.
A Simple JavaScript Module
Here's a small JavaScript example. Webpack would start from an entry file and follow imports like this to build its dependency graph.
Try running it to see what a basic script can do!
function createGreeting(name) {
return "Hello, " + name + "!";
}
// This could be your main app logic
const user = "CoddyKit Learner";
console.log(createGreeting(user));Output: Where Bundles Land
After Webpack finishes bundling, it needs a place to put the generated files. This is defined by the output property in your Webpack configuration.
path: Specifies the directory for the output files.filename: Defines the name of your bundled JavaScript file (e.g.,bundle.js).
Loaders: Beyond JavaScript
Webpack natively understands JavaScript and JSON files. But what about other file types like CSS, images, or TypeScript?
That's where Loaders come in! They act as translators, transforming these non-JavaScript files into valid modules that Webpack can process and add to your bundle.
Loader Example: Styling with CSS
A common use case for loaders is processing CSS. You'll often see css-loader and style-loader used together:
css-loader: Interprets@importandurl()likeimport/require().style-loader: Injects the CSS into the DOM.
This allows you to import CSS files directly into your JavaScript!
Plugins: Extending Webpack's Power
While loaders handle individual files, Plugins are more powerful. They can perform a wider range of tasks over the entire compilation process.
Plugins can:
- Optimize your bundle size.
- Manage assets like HTML files.
- Inject environment variables.
Plugin Example: HTMLWebpackPlugin
One very popular plugin is the HTMLWebpackPlugin. It simplifies HTML file creation for your bundles.
This plugin automatically generates an HTML file and injects your bundled JavaScript files into it. This is super helpful for deployment and cache busting!
The `webpack.config.js` File
All these settings – entry, output, loaders, and plugins – are configured in a special file: webpack.config.js.
This file is a standard Node.js module that exports a JavaScript object containing all your Webpack configuration options.
Quick Check: Webpack Tools
Which of the following Webpack features is responsible for transforming non-JavaScript files (like CSS or TypeScript) into modules that Webpack can understand?
Recap: Webpack's Core
Great job! In this lesson, we refreshed our understanding of Webpack's fundamental concepts:
- Bundling: Combining files to optimize performance.
- Entry Point: Where Webpack starts building its dependency graph.
- Output: Where the bundled files are saved.
- Loaders: Transforming non-JavaScript files into modules.
- Plugins: Extending Webpack's capabilities across the entire compilation.
Next, we'll dive into Module Federation!
자주 묻는 질문
“Webpack 기초 복습” 강의는 무료인가요?
네 — “Webpack 기초 복습” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Micro Frontends Architecture with Module Federation 강의 전체를 잠금 해제할 수 있습니다. Micro Frontends Architecture with Module Federation 강의에는 총 4개의 강의가 포함되어 있습니다.
“Webpack 기초 복습”에서 뭘 배우나요?
번들링, 로더, 플러그인을 비롯한 Webpack의 핵심 기능을 복습합니다. 브라우저에서 직접 실행하는 실습 코드로 Micro Frontends Architecture with Module Federation을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Micro Frontends Architecture with Module Federation을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Micro Frontends Architecture with Module Federation은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.
“Webpack 기초 복습” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Micro Frontends Architecture with Module Federation 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Micro Frontends Architecture with Module Federation 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- Webpack 기초 복습
- Module Federation 소개
- 호스트 애플리케이션과 원격 애플리케이션
- 공유 종속성 구성