webpack README

The project's README from github.com/webpack/webpack. As one markdown file: README.md.



[![npm][npm]][npm-url]

[![node][node]][node-url] [![builds1][builds1]][builds1-url] [![dependency-review][dependency-review]][dependency-review-url] [![coverage][cover]][cover-url] pkg.pr.new [![PR's welcome][prs]][prs-url] compatibility-score downloads install-size backers sponsors contributors discussions discord LFX Health Score Agent Friendly

webpack

Webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.

Table of Contents

Install

Install with npm:

npm install --save-dev webpack

Install with yarn:

yarn add webpack --dev

Introduction

Webpack is a bundler for modules. The main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.

TL;DR

Learn about webpack through videos!

Get Started

Check out webpack's quick Get Started guide and the other guides.

Browser Compatibility

Webpack supports all browsers that are ES5-compliant (IE8 and below are not supported). Webpack also needs Promise for import() and require.ensure(). If you want to support older browsers, you will need to load a polyfill before using these expressions.

Concepts

Plugins

Webpack has a rich plugin interface. Most of the features within webpack itself use this plugin interface. This makes webpack very flexible.

Webpack can generate HTML pages and extract CSS files itself, both experimental — see what that covers, and what still needs a plugin, for CSS and HTML.

Name Status Install Size Description
compression-webpack-plugin compression-npm compression-size Prepares compressed versions of assets to serve them with Content-Encoding
html-bundler-webpack-plugin bundler-npm bundler-size Renders a template (EJS, Handlebars, Pug) with referenced source asset files into HTML.
pug-plugin pug-plugin-npm pug-plugin-size Renders Pug files to HTML, extracts JS and CSS from sources specified directly in Pug.

Loaders

Webpack enables the use of loaders to preprocess files. This allows you to bundle any static resource way beyond JavaScript. You can easily write your own loaders using Node.js.

Loaders are activated by using loadername! prefixes in require() statements, or are automatically applied via regex from your webpack configuration.

JavaScript, JSON and assets need no loader, and CSS and HTML have experimental built-in support — but preprocessors and template engines keep their loaders.

JSON

Name Status Install Size Description
cson-npm cson-size Loads and transpiles a CSON file

Transpiling

Name Status Install Size Description
babel-npm babel-size Loads ES2015+ code and transpiles to ES5 using Babel
type-npm type-size Loads TypeScript like JavaScript
coffee-npm coffee-size Loads CoffeeScript like JavaScript

Templating

Name Status Install Size Description
pug-npm pug-size Compiles Pug to a function or HTML string, useful for use with Vue, React, Angular
md-npm md-size Compiles Markdown to HTML
posthtml-npm posthtml-size Loads and transforms a HTML file using PostHTML
hbs-npm hbs-size Compiles Handlebars to HTML

Styling

Name Status Install Size Description
less-npm less-size Loads and compiles a LESS file
sass-npm sass-size Loads and compiles a Sass/SCSS file
stylus-npm stylus-size Loads and compiles a Stylus file
postcss-npm postcss-size Loads and transforms a CSS/SSS file using PostCSS

Frameworks

Name Status Install Size Description
vue-npm vue-size Loads and compiles Vue Components
polymer-npm polymer-size Process HTML & CSS with preprocessor of choice and require() Web Components like first-class modules
angular-npm angular-size Loads and compiles Angular 2 Components
riot-npm riot-size Riot official webpack loader
svelte-npm svelte-size Official Svelte loader

Performance

Webpack uses async I/O and has multiple caching levels. This makes webpack fast and incredibly fast on incremental compilations.

Module Formats

Webpack supports ES2015+, CommonJS and AMD modules out of the box. It performs clever static analysis on the AST of your code. It even has an evaluation engine to evaluate simple expressions. This allows you to support most existing libraries out of the box.

Code Splitting

Webpack allows you to split your codebase into multiple chunks. Chunks are loaded asynchronously at runtime. This reduces the initial loading time.

Optimizations

Webpack can do many optimizations to reduce the output size of your JavaScript by deduplicating frequently used modules, minifying, and giving you full control of what is loaded initially and what is loaded at runtime through code splitting. It can also make your code chunks cache friendly by using hashes.

Developer Tools

If you're working on webpack itself, or building advanced plugins or integrations, the tools below can help you explore internal mechanics, debug plugin life-cycles, and build custom tooling.

Instrumentation

| Name | Status

webpack (webpack/webpack)

Searching Database…

这是什么?Webpack 是一个面向 JavaScript 及相关文件的模块打包工具:它把许多模块(JS、CSS、图片、JSON 等)打包成少数几个资源文件,供浏览器使用。
这是独立应用,还是我在构建过程中运行的工具?它是一个在构建时使用的 CLI/库工具:你将其安装为开发依赖,运行它把项目模块编译成输出包。终端用户不会直接与它交互。
如何把 webpack 添加到项目中?用 npm 或 yarn 将其安装为项目依赖,然后用 webpack 配置文件进行配置,并运行 webpack 命令来打包你的文件。
使用前还需要安装其他东西吗?需要安装 Node.js(引擎要求为 node >=10.13.0),以及用于安装它的 npm 或 yarn;不需要其他运行环境。
它能在 IE8 这样的旧浏览器中运行吗?Webpack 支持所有兼容 ES5 的浏览器,但明确不支持 IE8 及更低版本。在旧浏览器上,使用 import() 和 require.ensure() 还需要 Promise 填充库(polyfill)。
webpack 能理解哪些模块格式?它开箱即支持 ES2015+ 模块、CommonJS 和 AMD,即使混合使用也可以,方式是对代码的 AST 进行静态分析。
webpack 如何降低首次加载时间?它支持代码分割,允许你把代码库拆分成多个代码块,在运行时异步加载,而不是只输出一个庞大的包。
加载器有什么用?加载器在打包前预处理非 JS 文件,例如把 TypeScript 或 CoffeeScript 转译为 JavaScript,把 Sass/LESS 编译为 CSS,或把图片转换为 Base64。
webpack 不借助插件就能生成 HTML 并提取 CSS 吗?webpack 本身对生成 HTML 页面和提取 CSS 有实验性的内置支持,但更复杂的场景仍需依赖插件,例如 html-bundler-webpack-plugin 或 pug-plugin。
Creator
webpack
Size
129.1 MB
Stars
66K
Age
14y
Commits · 90 Days