2021-05-24 11:14:10 +00:00
|
|
|
import type { Nuxt } from '../types/nuxt'
|
2021-04-02 11:47:01 +00:00
|
|
|
import {
|
|
|
|
addTemplate,
|
|
|
|
addErrorLayout,
|
|
|
|
addLayout,
|
|
|
|
addPlugin,
|
|
|
|
addServerMiddleware,
|
|
|
|
extendBuild,
|
|
|
|
extendRoutes
|
|
|
|
} from './utils'
|
2021-05-24 11:14:10 +00:00
|
|
|
import { installModule } from './install'
|
2021-04-02 11:47:01 +00:00
|
|
|
|
2021-04-15 18:49:29 +00:00
|
|
|
/** Legacy ModuleContainer for backwards compatibility with existing Nuxt 2 modules. */
|
2021-06-25 09:37:18 +00:00
|
|
|
export function createModuleContainer (nuxt: Nuxt) {
|
|
|
|
return {
|
|
|
|
nuxt,
|
|
|
|
options: nuxt.options,
|
2021-04-02 11:47:01 +00:00
|
|
|
|
2021-06-25 09:37:18 +00:00
|
|
|
/**
|
|
|
|
* Returns a resolved promise immediately.
|
|
|
|
*
|
|
|
|
* @deprecated
|
|
|
|
*/
|
|
|
|
ready () {
|
|
|
|
return Promise.resolve()
|
|
|
|
},
|
2021-04-02 11:47:01 +00:00
|
|
|
|
2021-06-25 09:37:18 +00:00
|
|
|
/** @deprecated */
|
|
|
|
addVendor () {
|
|
|
|
console.warn('addVendor has been deprecated and has no effect.')
|
|
|
|
},
|
2021-04-02 11:47:01 +00:00
|
|
|
|
2021-06-25 09:37:18 +00:00
|
|
|
/**
|
|
|
|
* Renders given template using lodash template during build into the project buildDir (`.nuxt`).
|
|
|
|
*
|
|
|
|
* If a fileName is not provided or the template is string, target file name defaults to
|
|
|
|
* [dirName].[fileName].[pathHash].[ext].
|
|
|
|
*/
|
|
|
|
addTemplate,
|
2021-04-02 11:47:01 +00:00
|
|
|
|
2021-06-25 09:37:18 +00:00
|
|
|
/**
|
|
|
|
* Registers a plugin using `addTemplate` and prepends it to the plugins[] array.
|
|
|
|
*
|
|
|
|
* Note: You can use mode or .client and .server modifiers with fileName option
|
|
|
|
* to use plugin only in client or server side.
|
|
|
|
*
|
|
|
|
* If you choose to specify a fileName, you can configure a custom path for the
|
|
|
|
* fileName too, so you can choose the folder structure inside .nuxt folder in
|
|
|
|
* order to prevent name collisioning:
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```js
|
|
|
|
* this.addPlugin({
|
|
|
|
* src: path.resolve(__dirname, 'templates/foo.js'),
|
|
|
|
* fileName: 'foo.server.js' // [optional] only include in server bundle
|
|
|
|
* })
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
addPlugin,
|
2021-04-02 11:47:01 +00:00
|
|
|
|
2021-06-25 09:37:18 +00:00
|
|
|
/** Register a custom layout. If its name is 'error' it will override the default error layout. */
|
|
|
|
addLayout,
|
2021-04-02 11:47:01 +00:00
|
|
|
|
2021-06-25 09:37:18 +00:00
|
|
|
/**
|
|
|
|
* Set the layout that will render Nuxt errors. It should already have been added via addLayout or addTemplate.
|
|
|
|
*
|
|
|
|
* @param dst - Path to layout file within the buildDir (`.nuxt/<dst>.vue`)
|
|
|
|
*/
|
|
|
|
addErrorLayout,
|
2021-04-02 11:47:01 +00:00
|
|
|
|
2021-06-25 09:37:18 +00:00
|
|
|
/** Adds a new server middleware to the end of the server middleware array. */
|
|
|
|
addServerMiddleware,
|
2021-04-02 11:47:01 +00:00
|
|
|
|
2021-06-25 09:37:18 +00:00
|
|
|
/** Allows extending webpack build config by chaining `options.build.extend` function. */
|
|
|
|
extendBuild,
|
2021-04-02 11:47:01 +00:00
|
|
|
|
2021-06-25 09:37:18 +00:00
|
|
|
/** Allows extending routes by chaining `options.build.extendRoutes` function. */
|
|
|
|
extendRoutes,
|
2021-04-02 11:47:01 +00:00
|
|
|
|
2021-06-25 09:37:18 +00:00
|
|
|
/** `requireModule` is a shortcut for `addModule` */
|
|
|
|
requireModule: installModule,
|
2021-04-02 11:47:01 +00:00
|
|
|
|
2021-06-25 09:37:18 +00:00
|
|
|
/** Registers a module. moduleOpts can be a string or an array ([src, options]). */
|
|
|
|
addModule: installModule
|
2021-04-02 11:47:01 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-25 09:37:18 +00:00
|
|
|
|
|
|
|
export type ModuleContainer = ReturnType<typeof createModuleContainer>
|