Want to take a look at our new docs? Our 
        
          new docs
        
        are now in beta. Have fun!
      
API: The ModuleContainer Class
ModuleContainer Class
- 来源: core/module.js
所有模块都将在ModuleContainer实例的context调用。
Tapable plugins
我们可以在某些生命周期事件中注册 hooks。
nuxt.moduleContainer.plugin('ready', async moduleContainer => {
  // Do this after all modules where ready
})
在 modules 的context中我们可以使用它:
this.plugin('ready', async moduleContainer => {
  // Do this after all modules where ready
})
| 插件 | 参数 | 说明 | 
|---|---|---|
| ready | moduleContainer | nuxt.config.js中的所有模块都已初始化 | 
方法
添加 Vendor(vendor)
vendor已经废弃不再使用
添加到options.build.vendor并应用唯一插件过滤器。
添加到模板中 (template)
- template: StringorObject- src
- options
- fileName
 
在构建到项目buildDir (.nuxt)期间使用lodash 模板渲染指定模板。
如果未提供fileName或template为string,则目标文件名默认为[dirName].[fileName].[pathHash].[ext]。
这个方法将返回 { dist, src, options } 对象.
添加插件 (template)
使用addTemplate注册插件并将其添加到 plugins[]选项。
您可以使用template.ssr: false来禁用包含在 SSR 中的插件。
添加服务器端渲染中间件 (middleware)
将中间件插入 options.serverMiddleware.
extendBuild (fn)
Allows easily extending webpack build config by chaining options.build.extend function.
extendRoutes (fn)
允许通过链接options.build.extendRoutes函数轻松扩展 webpack 构建配置。
添加模块 (moduleOpts, requireOnce)
注册模块。moduleOpts可以是string或[src, options]。如果requireOnce为true且已解析的模块导出meta阻止两次注册相同的模块。
requireModule (moduleOpts)
addModule(moduleOpts, true)
Hooks
我们可以在某些生命周期事件中注册钩子。
| Hook | Arguments | When | 
|---|---|---|
| modules:before | (moduleContainer, options) | 在创建 ModuleContainer 类之前调用 ,对重载方法和选项很有用。 | 
| modules:done | (moduleContainer) | 加载所有模块时调用。 | 
