defineExtension
Extensions are registered in the application using the
front-commerce.config.ts
file. Read
Register an extension to learn more.
defineExtension
defineExtension
allows you to define extensions settings
defineExtension(configuration);
Arguments:
Name | Type | Description |
---|---|---|
configuration | ExtensionConfig | The extension configuration |
Example:
defineExtension({
name: "acme",
meta: import.meta,
theme: "./extensions/acme/theme",
});
ExtensionConfig
ExtensionConfig
is the definition interface of an extension.
name
Required string
Specifies the unique name of the extension.
Example:
{
"name": "acme"
}
meta
Since version 3.4
Required string
Specifies the
ImportMeta
information of the extension.
Example:
{
"meta": import.meta
}
The import.meta
should be from the root of your extension. If you defined your
extension under a sub-directory, then you should re-export it from the root
instead.
📁 hello-v3/
│ ├── 📁 app/
│ ├── 📄 front-commerce.config.ts
│ ├── 📁 extensions/
│ │ ├── 📁 acme-extension/
│ │ │ ├── 📄 index.ts # this is where the import.meta should be located
│ │ │ ├── 📁 extension-def/
│ │ │ │ └── 📄 index.ts
│ │ │ ├── 📁 graphql/
│ │ │ └── 📁 routes/
└── package.json
configuration
Required object
Define configuration
providers
Required ConfigProvider[]
Define configuration provider
theme
Optional string|string[]
Specifies the path to the theme that should
be loaded by the application.
Example:
{
"theme": "./extensions/acme/theme"
}
graphql
Optionnal
Configuration for registering GraphQL modules in the unified GraphQL schema.
schema
Optional string|string[]
Defines path(s) to the GraphQL schema file(s)
to be loaded in the application.
Example:
{
"schema": [
"./extensions/acme/graphql/foo/**/schema.gql", // accepts a globby pattern
"./extensions/acme/graphql/bar/Feature.gql" // accepts a direct path
]
}
codegen
Optional
CodegenConfig["generates"][] | CodegenConfig["generates"]
configuration
for code generation.
translations
Optional string
Specifies the path to the translations directory that
should be compiled by the application.
Example:
{
"translations": "./extensions/acme/translations"
}
unstable_lifecycleHooks
This feature is unstable and may change in the future.
Optional
Specifies the lifecycle hooks that should be executed by the application. These hooks allow you to register custom logic at specific points of the application lifecycle.
Example:
{
unstable_lifecycleHooks: {
onServerInit: async (globalServices) => {
// Do something when the server is initialized
};
onServerServicesInit: async (serverServices, request, config) => {
// Do something when the request is initialized
};
onFeaturesInit: async (hooks) => {
// Do something when the features are initialized
};
}
}
onServerInit
Since version 3.6
Called when the server is initialized with the following params:
Global Services
- Generally used to register new services
onServerServicesInit
Called on each request with the following params:
Server Services
- Generally used to register new servicesRequest
- The request objectResolvedConfig
- The resolved configuration object
onFeaturesInit
Called when the features are initialized with the following params:
FeatureHooks
- The features hooks object