Skip to content

Commit 850374e

Browse files
authored
Fix #2052 (#2075)
1 parent d50433d commit 850374e

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

docusaurus/docs/dev-docs/plugins-extension.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ Plugin extensions code is located in the `./src/extensions` folder (see [project
2121
```bash
2222
/extensions
2323
/some-plugin-to-extend
24-
strapi-server.js
24+
strapi-server.js|ts
2525
/content-types
2626
/some-content-type-to-extend
2727
model.json
2828
/another-content-type-to-extend
2929
model.json
3030
/another-plugin-to-extend
31-
strapi-server.js
31+
strapi-server.js|ts
3232
```
3333
</details>
3434

@@ -39,13 +39,13 @@ Plugins can be extended in 2 ways:
3939

4040
## Extending a plugin's content-types
4141

42-
A plugin's Content-Types can be extended in 2 ways: using the programmatic interface within `strapi-server.js` and by overriding the content-types schemas.
42+
A plugin's Content-Types can be extended in 2 ways: using the programmatic interface within `strapi-server.js|ts` and by overriding the content-types schemas.
4343

4444
The final schema of the content-types depends on the following loading order:
4545

4646
1. the content-types of the original plugin,
4747
2. the content-types overridden by the declarations in the [schema](/dev-docs/backend-customization/models#model-schema) defined in `./src/extensions/plugin-name/content-types/content-type-name/schema.json`
48-
3. the content-types declarations in the [`content-types` key exported from `strapi-server.js`](/dev-docs/api/plugins/server-api#content-types)
48+
3. the content-types declarations in the [`content-types` key exported from `strapi-server.js|ts`](/dev-docs/api/plugins/server-api#content-types)
4949
4. the content-types declarations in the [`register()` function](/dev-docs/configurations/functions#register) of the Strapi application
5050

5151
To overwrite a plugin's [content-types](/dev-docs/backend-customization/models):
@@ -63,23 +63,27 @@ When a Strapi application is initializing, plugins, extensions and global lifecy
6363

6464
1. Plugins are loaded and their interfaces are exposed.
6565
2. Files in `./src/extensions` are loaded.
66-
3. The `register()` and `bootstrap()` functions in `./src/index.js` are called.
66+
3. The `register()` and `bootstrap()` functions in `./src/index.js|ts` are called.
6767

68-
A plugin's interface can be extended at step 2 (i.e. within `./src/extensions`) or step 3 (i.e. inside `./src/index.js`).
68+
A plugin's interface can be extended at step 2 (i.e. within `./src/extensions`) or step 3 (i.e. inside `./src/index.js|ts`).
69+
70+
:::note
71+
If your Strapi project is TypeScript-based, please ensure that the `index` file has a TypeScript extension (i.e., `src/index.ts`) otherwise it will not be compiled.
72+
:::
6973

7074
### Within the extensions folder
7175

7276
To extend a plugin's server interface using the `./src/extensions` folder:
7377

7478
1. _(optional)_ Create the `./src/extensions` folder at the root of the app, if the folder does not already exist.
7579
2. Create a subfolder with the same name as the plugin to be extended.
76-
3. Create a `strapi-server.js` file to extend a plugin's back end using the [Server API](/dev-docs/api/plugins/server-api).
80+
3. Create a `strapi-server.js|ts` file to extend a plugin's back end using the [Server API](/dev-docs/api/plugins/server-api).
7781
4. Within this file, define and export a function. The function receives the `plugin` interface as an argument so it can be extended.
7882

7983
<details>
8084
<summary>Example of backend extension</summary>
8185

82-
```js title="./src/extensions/some-plugin-to-extend/strapi-server.js"
86+
```js title="./src/extensions/some-plugin-to-extend/strapi-server.js|ts"
8387

8488
module.exports = (plugin) => {
8589
plugin.controllers.controllerA.find = (ctx) => {};
@@ -99,12 +103,12 @@ module.exports = (plugin) => {
99103

100104
### Within the register and bootstrap functions
101105

102-
To extend a plugin's interface within `./src/index.js`, use the `bootstrap()` and `register()` [functions](/dev-docs/configurations/functions) of the whole project, and access the interface programmatically with [getters](/dev-docs/api/plugins/server-api#usage).
106+
To extend a plugin's interface within `./src/index.js|ts`, use the `bootstrap()` and `register()` [functions](/dev-docs/configurations/functions) of the whole project, and access the interface programmatically with [getters](/dev-docs/api/plugins/server-api#usage).
103107

104108
<details>
105-
<summary>Example of extending a plugin's content-type within ./src/index.js</summary>
109+
<summary>Example of extending a plugin's content-type within ./src/index.js|ts</summary>
106110

107-
```js title="./src/index.js"
111+
```js title="./src/index.js|ts"
108112

109113
module.exports = {
110114
register({ strapi }) {

0 commit comments

Comments
 (0)