非常教程

Webpack参考手册

接口 | API

解析 | Resolver

有三种类型的解析器,每种都用于不同类型的模块:

  • compiler.resolvers.normal

通过绝对路径或相对路径,解析一个模块

  • compiler.resolvers.context:解析上下文模块。
  • compiler.resolvers.loader:解析加载器。

任何插件都应该this.fileSystem用作fileSystem,因为它已被缓存。它只具有异步命名功能,但如果用户使用同步文件系统实现(即在增强需求中),它们可能会同步。

要加入任何插件应使用的路径this.join。它规范了路径。还有一个this.normalize

保存异步forEach实现可用this.forEachBail(array, iterator, callback)

要将请求传递给其他解析插件,请使用该this.doResolve(types: String|String[], request: Request, message: String, callback)方法。types是按优先顺序测试的多种可能的请求类型。

interface Request {
  path: String // The current directory of the request
  request: String // The current request string
  query: String // The query string of the request, if any
  module: boolean // The request begins with a module
  directory: boolean // The request points to a directory
  file: boolean // The request points to a file
  resolved: boolean // The request is resolved/done
  // undefined means false for boolean fields
}

// Examples
// from /home/user/project/file.js: require("../test?charset=ascii")
{
  path: "/home/user/project",
  request: "../test",
  query: "?charset=ascii"
}
// from /home/user/project/file.js: require("test/test/")
{
  path: "/home/user/project",
  request: "test/test/",
  module: true,
  directory: true
}

resolve(context: String, request: String)

解决过程开始之前。

resolve-step(types: String[], request: Request)

解决过程中的一个步骤开始之前。

module(request: Request) async waterfall

找到了一个模块请求,应该解决。

directory(request: Request) async waterfall

目录请求被找到并且应该被解决。

file(request: Request) async waterfall

找到了一个文件请求,应该解决。

插件可能会提供更多的扩展点

这里列出了webpack提供的默认插件列表。他们都是(request: Request)异步瀑布。

正常模块和上下文的过程是module -> module-module -> directory -> file

装载机的过程是module -> module-loader-module -> module-module -> directory -> file

module-module

应该在指定的目录中查找模块。path包含目录。

module-loader-module (仅适用于装载机)

在将模板模板应用于模块名称之前使用。该过程继续module-module

Webpack

webpack 是一个模块打包器。webpack 处理带有依赖关系的模块,生成一系列表示这些模块的静态资源。

主页 https://webpack.js.org/
源码 https://github.com/webpack/webpack
发布版本 3.8.1

Webpack目录

1.指南 | Guides
2.接口 | API
3.概念 | Concepts
4.组态 | Configuration
5.装载 | Loaders