92 lines
2.7 KiB
Plaintext
92 lines
2.7 KiB
Plaintext
---
|
|
title: Webpack
|
|
label: Webpack
|
|
order: 80
|
|
desc: The Payload admin panel uses Webpack 5 and supports many common functionalities such as SCSS and Typescript out of the box to give you more freedom.
|
|
keywords: admin, webpack, documentation, Content Management System, cms, headless, javascript, node, react, express
|
|
---
|
|
|
|
Payload has a Webpack (v5) bundler that you can build the Admin panel with. We recommended using it because it is stable. If you are feeling a bit more adventurous you can give the Vite bundler shot.
|
|
|
|
Out of the box the Webpack bundler supports common functionalities such as SCSS and Typescript, but there are many cases where you may need to add support for additional functionalities.
|
|
|
|
To use webpack as your bundler, you must install it:
|
|
|
|
```bash
|
|
yarn add @payloadcms/bundler-webpack
|
|
```
|
|
|
|
After installing, set the `bundler: webpackBundler()` on your Payload config. If you would like to extend the Webpack config, you can do so by passing a function to the webpack property.
|
|
|
|
```ts
|
|
// payload.config.ts
|
|
|
|
import { buildConfig } from 'payload/config'
|
|
import { webpackBundler } from '@payloadcms/bundler-webpack'
|
|
|
|
export default buildConfig({
|
|
admin: {
|
|
// highlight-start
|
|
bundler: webpackBundler()
|
|
webpack: (config) => {
|
|
// full control of the Webpack config
|
|
|
|
return config
|
|
},
|
|
// highlight-end
|
|
},
|
|
// rest of your payload config
|
|
})
|
|
```
|
|
|
|
### Aliasing server-only modules
|
|
|
|
To remove files that contain server-only modules from your bundle, you can use the `alias` Webpack feature.
|
|
|
|
First create a mock module that exports an empty object:
|
|
```js
|
|
// mocks/emptyObject.js
|
|
|
|
export default {}
|
|
```
|
|
|
|
Then, in your Payload config, you can alias the file containing the server-only module to the mock module:
|
|
```ts
|
|
// payload.config.ts
|
|
|
|
import { buildConfig } from 'payload/config'
|
|
import { webpackBundler } from '@payloadcms/bundler-webpack'
|
|
|
|
const mockModulePath = path.resolve(__dirname, 'mocks/emptyObject.js')
|
|
const pathToFileWithServerOnlyModule = path.resolve(__dirname, 'hooks/syncStripeCustomer.ts')
|
|
|
|
export default buildConfig({
|
|
admin: {
|
|
bundler: webpackBundler(),
|
|
webpack: (config) => {
|
|
return {
|
|
...config,
|
|
resolve: {
|
|
...config.resolve,
|
|
// highlight-start
|
|
alias: {
|
|
...config.resolve.alias,
|
|
[pathToFileWithServerOnlyModule]: mockModulePath,
|
|
},
|
|
// highlight-end
|
|
},
|
|
}
|
|
},
|
|
},
|
|
// rest of your payload config
|
|
})
|
|
```
|
|
|
|
<Banner type="success">
|
|
<strong>Tip:</strong>
|
|
<br />
|
|
If changes to your Webpack aliases are not surfacing, they might be
|
|
[cached](https://webpack.js.org/configuration/cache/) in `node_modules/.cache/webpack`. Try
|
|
deleting that folder and restarting your server.
|
|
</Banner>
|