Skip to content

Commit 9979c26

Browse files
Merge pull request #1963 from strapi/feat/add-vite
Add vite bundler documentation to admin panel customisation
2 parents 93e14ab + 50e803d commit 9979c26

File tree

2 files changed

+115
-29
lines changed

2 files changed

+115
-29
lines changed

docusaurus/docs/dev-docs/admin-panel-customization.md

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import FeedbackCallout from '/docs/snippets/backend-customization-feedback-cta.m
1010
const captionStyle = {fontSize: '12px'}
1111
const imgStyle = {width: '100%', margin: '0' }
1212

13-
The admin panel is a `node_module` that is similar to a plugin, except that it encapsulates all the installed plugins of a Strapi application. Some of its aspects can be [customized](#customization-options), and plugins can also [extend](#extension) it.
13+
The admin panel is a React-based single-page application. It encapsulates all the installed plugins of a Strapi application. Some of its aspects can be [customized](#customization-options), and plugins can also [extend](#extension) it.
1414

1515
To start your strapi instance with hot reloading while developing, run the following command:
1616

1717
```bash
1818
cd my-app # cd into the root directory of the Strapi application project
19-
strapi develop
19+
strapi develop --watch-admin
2020
```
2121

2222
## Customization options
@@ -27,7 +27,6 @@ Customizing the admin panel is helpful to better reflect your brand identity or
2727
- The [configuration object](#configuration-options) allows replacing the logos and favicon, defining locales and extending translations, extending the theme, and disabling some Strapi default behaviors like displaying video tutorials or notifications about new Strapi releases.
2828
- The [WYSIWYG editor](#wysiwyg-editor) can be replaced or customized.
2929
- The [email templates](#email-templates) should be customized using the Users and Permissions plugin.
30-
- The [webpack configuration](#webpack-configuration) based on webpack 5 can also be extended for advanced customization
3130

3231
### Access URL
3332

@@ -537,15 +536,24 @@ export default {
537536

538537
Email templates should be edited through the admin panel, using the [Users and Permissions plugin settings](/user-docs/settings/configuring-users-permissions-plugin-settings#configuring-email-templates).
539538

540-
### Webpack configuration
539+
## Bundlers (experimental)
540+
541+
2 different bundlers can be used with your Strapi application, [webpack](#webpack) and [vite](#vite).
542+
543+
### Webpack
544+
545+
In v4 this is the defacto bundler that Strapi uses to build the admin panel.
541546

542547
:::prerequisites
543-
Make sure to rename the default `webpack.config.example.js` file into `webpack.config.js` before customizing webpack.
548+
Make sure to rename the default `webpack.config.example.js` file into `webpack.config.[js|ts]` before customizing webpack.
544549
:::
545550

546-
In order to extend the usage of webpack v5, define a function that extends its configuration inside `./my-app/src/admin/webpack.config.js`:
551+
In order to extend the usage of webpack v5, define a function that extends its configuration inside `./my-app/src/admin/webpack.config.[js|ts]`:
547552

548-
```js
553+
<Tabs groupId="js-ts">
554+
<TabItem value="js" label="JavaScript">
555+
556+
```js title="./my-app/src/admin/webpack.config.js"
549557
module.exports = (config, webpack) => {
550558
// Note: we provide webpack above so you should not `require` it
551559

@@ -557,10 +565,79 @@ module.exports = (config, webpack) => {
557565
};
558566
```
559567

560-
:::note
561-
Only `./src/admin/app.js` and the files under the `./src/admin/extensions` folder are being watched by the webpack dev server.
568+
</TabItem>
569+
570+
<TabItem value="ts" label="TypeScript">
571+
572+
```ts title="./my-app/src/admin/webpack.config.ts"
573+
export default (config, webpack) => {
574+
// Note: we provide webpack above so you should not `require` it
575+
576+
// Perform customizations to webpack config
577+
config.plugins.push(new webpack.IgnorePlugin(/\/__tests__\//));
578+
579+
// Important: return the modified config
580+
return config;
581+
};
582+
```
583+
584+
</TabItem>
585+
</Tabs>
586+
587+
### Vite
588+
589+
:::caution
590+
This is considered experimental. Please report any issues you encounter.
562591
:::
563592

593+
To use `vite` as a bundler you will need to pass it as an option to the `strapi develop` command:
594+
595+
```bash
596+
strapi develop --watch-admin --bundler=vite
597+
```
598+
599+
To extend the usage of `vite`, define a function that extends its configuration inside `./my-app/src/admin/vite.config.[js|ts]`:
600+
601+
<Tabs groupId="js-ts">
602+
<TabItem value="js" label="JavaScript">
603+
604+
```js title="./my-app/src/admin/vite.config.js"
605+
const { mergeConfig } = require("vite");
606+
607+
module.exports = (config) => {
608+
// Important: always return the modified config
609+
return mergeConfig(config, {
610+
resolve: {
611+
alias: {
612+
"@": "/src",
613+
},
614+
},
615+
});
616+
};
617+
```
618+
619+
</TabItem>
620+
621+
<TabItem value="ts" label="TypeScript">
622+
623+
```ts title="./my-app/src/admin/vite,config.ts"
624+
import { mergeConfig } from "vite";
625+
626+
export default (config) => {
627+
// Important: always return the modified config
628+
return mergeConfig(config, {
629+
resolve: {
630+
alias: {
631+
"@": "/src",
632+
},
633+
},
634+
});
635+
};
636+
```
637+
638+
</TabItem>
639+
</Tabs>
640+
564641
## Extension
565642

566643
There are 2 use cases to extend the admin panel:

docusaurus/docs/dev-docs/cli.md

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,30 @@ Strapi modifies/creates files at runtime and needs to restart when new files are
5959

6060
Strapi also adds middlewares to support HMR (Hot Module Replacement) for the administration panel. This allows you to customize the administration panel without having to restart the application or run a separate server. This is only added when you use the `--watch-admin` command.
6161

62-
```
62+
```bash
6363
strapi develop
64-
options: [--no-build |--watch-admin |--browser |--debug |--silent]
6564
```
6665

67-
- **strapi develop**<br/>
68-
Starts your application with the autoReload enabled
69-
- **strapi develop --open**<br/>
70-
Starts your application with the autoReload enabled & open your default browser with the administration panel running.
71-
- **strapi develop --watch-admin**<br/>
72-
Starts your application with the autoReload enabled and the front-end development server. It allows you to customize the administration panel.
73-
- [DEPRECATED] **strapi develop --no-build**<br/>
74-
Starts your application with the autoReload enabled and skip the administration panel build process
75-
- [DEPRECATED] **strapi develop --watch-admin --browser 'google chrome'**<br/>
76-
Starts your application with the autoReload enabled and the front-end development server. It allows you to customize the administration panel. Provide a browser name to use instead of the default one, `false` means stop opening the browser.
66+
| Option | Type | Description | Default |
67+
| ------------------ | :----: | ---------------------------------------------------------------------------------------------------------------- | --------- |
68+
| `--bundler` | string | Specifies the bundler to use, either `webpack` or `vite`x | `webpack` |
69+
| `-d, --debug` | - | Enable debugging mode with verbose logs | false |
70+
| `--ignore-prompts` | - | Ignore all prompts | false |
71+
| `--open` | - | Open the admin in your browser (default: true) | false |
72+
| `--polling` | - | Watch for file changes in network directories | false |
73+
| `--silent` | - | Don't log anything | false |
74+
| `--watch-admin` | - | Watch the admin panel for hot changes | false |
75+
| `--no-build` | - | [DEPRECATED] Starts your application with the autoReload enabled and skip the administration panel build process | - |
76+
| `--browser` | string | [DEPRECATED] Provide a browser name to use instead of the default one | - |
7777

7878
:::warning
7979
You should never use this command to run a Strapi application in production.
8080
:::
8181

82+
:::caution
83+
Using the `vite` option as a bundler is considered experimental.
84+
:::
85+
8286
## strapi start
8387

8488
Start a Strapi application with autoReload disabled.
@@ -94,14 +98,19 @@ Builds your admin panel.
9498
strapi build
9599
```
96100

97-
| Option | Type | Description |
98-
| ------------------- | :--: | -------------------------------------------------------- |
99-
| `-d, --debug` | - | Enable debugging mode with verbose logs (default: false) |
100-
| `--minify` | - | Minify the output (default: true) |
101-
| `--no-optimization` | - | [DEPRECATED]: use minify instead |
102-
| `--silent` | - | Don't log anything (default: false) |
103-
| `--sourcemaps` | - | Produce sourcemaps (default: false) |
104-
| `--stats` | - | Print build statistics to the console (default: false) |
101+
| Option | Type | Description | Default |
102+
| ------------------- | :----: | ------------------------------------------------------------------- | --------- |
103+
| `--bundler` | string | Specifies the bundler you'd like to use, either `webpack` or `vite` | `webpack` |
104+
| `-d, --debug` | - | Enable debugging mode with verbose logs | false |
105+
| `--minify` | - | Minify the output | true |
106+
| `--no-optimization` | - | [DEPRECATED]: use minify instead | - |
107+
| `--silent` | - | Don't log anything | false |
108+
| `--sourcemaps` | - | Produce sourcemaps | false |
109+
| `--stats` | - | Print build statistics to the console | false |
110+
111+
:::caution
112+
Using the `vite` option as a bundler is considered experimental.
113+
:::
105114

106115
## strapi watch-admin
107116

0 commit comments

Comments
 (0)