Skip to content
This repository was archived by the owner on Mar 16, 2026. It is now read-only.

Commit 8c1e78d

Browse files
committed
docs: add custom webpack config
1 parent 4d896cc commit 8c1e78d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
name: Customizing Webpack Config
3+
route: /docs/customizing-webpack-config
4+
parent: Documentation
5+
menu: Customizing
6+
---
7+
8+
# Customizing docz's Webpack Configuration
9+
10+
Let's assume we want to configure an alias so that instead of importing files from `../../components/Alert` we import from `@/components/Alert`.
11+
12+
And another alias to allow us to replace relative paths like `import A from './src/components/Alert` with an absolute path `import A from 'components/Alert'`
13+
14+
To configure the webpack config we add a `gatsby-node.js` file at the root of the project and export `onCreateWebpackConfig` like we would normally do in a Gatsby app.
15+
16+
You can read more about configuring webpack with Gatsby [here](https://www.gatsbyjs.org/docs/add-custom-webpack-config/), see a small example below and a full working example [here](https://github.com/doczjs/docz/tree/master/examples/webpack-alias) :
17+
18+
19+
```js
20+
// gatsby-node.js
21+
const path = require('path')
22+
exports.onCreateWebpackConfig = args => {
23+
args.actions.setWebpackConfig({
24+
resolve: {
25+
// ⚠ Note the '..' in the path because the docz gatsby project lives in the `.docz` directory
26+
modules: [path.resolve(__dirname, '../src'), 'node_modules'],
27+
alias: {
28+
'@': path.resolve(__dirname, '../src/components/'),
29+
},
30+
},
31+
})
32+
}
33+
```

0 commit comments

Comments
 (0)