Skip to content
This repository was archived by the owner on Nov 21, 2025. It is now read-only.

Commit da5ccd6

Browse files
committed
docs: add webpack alias example
1 parent 334cb10 commit da5ccd6

File tree

8 files changed

+193
-0
lines changed

8 files changed

+193
-0
lines changed

examples/webpack-alias/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.docz
2+
node_modules

examples/webpack-alias/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Docz example with webpack aliases
2+
3+
## Using `create-docz-app`
4+
5+
```sh
6+
npx create-docz-app docz-app-webpack-alias --example webpack-alias
7+
# or
8+
yarn create docz-app docz-app-webpack-alias --example webpack-alias
9+
```
10+
11+
## Download manually
12+
13+
```sh
14+
curl https://codeload.github.com/doczjs/docz/tar.gz/master | tar -xz --strip=2 docz-master/examples/webpack-alias
15+
mv webpack-alias docz-webpack-alias-example
16+
cd docz-webpack-alias-example
17+
```
18+
19+
## Notes
20+
21+
To configure the webpack config we add a `gatsby-node.js` file and export `onCreateWebpackConfig`. More info here : https://www.gatsbyjs.org/docs/add-custom-webpack-config/
22+
23+
For this example, files inside `./src/` can be accessed with an absolute path. For example instead of doing `import A from './src/components/Alert` you can do `import A from 'components/Alert'`.
24+
25+
Another alias is set in place to map files in `./src/components/` to `@`. For example instead of doing `import A from './src/components/Alert` you can do `import A from '@/Alert'`.
26+
27+
```js
28+
// gatsby-node.js
29+
const path = require('path')
30+
31+
exports.onCreateWebpackConfig = args => {
32+
args.actions.setWebpackConfig({
33+
resolve: {
34+
// Note the '..' in the path because the docz gatsby project lives in the `.docz` directory
35+
modules: [path.resolve(__dirname, '../src'), 'node_modules'],
36+
alias: {
37+
'@': path.resolve(__dirname, '../src/components/'),
38+
},
39+
},
40+
})
41+
}
42+
43+
```
44+
45+
## Setup
46+
47+
```sh
48+
yarn # npm i
49+
```
50+
51+
## Run
52+
53+
```sh
54+
yarn dev # npm run dev
55+
```
56+
57+
## Build
58+
59+
```sh
60+
yarn build # npm run build
61+
```
62+
63+
## Serve built app
64+
65+
```sh
66+
yarn serve # npm run serve
67+
```

examples/webpack-alias/doczrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
menu: ['Getting Started', 'Components'],
3+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const path = require('path')
2+
3+
exports.onCreateWebpackConfig = args => {
4+
args.actions.setWebpackConfig({
5+
resolve: {
6+
modules: [path.resolve(__dirname, '../src'), 'node_modules'],
7+
alias: {
8+
'@': path.resolve(__dirname, '../src/components/'),
9+
},
10+
},
11+
})
12+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "docz-example-basic",
3+
"private": true,
4+
"version": "2.0.0-rc.41",
5+
"license": "MIT",
6+
"files": [
7+
"src/",
8+
"doczrc.js",
9+
"package.json"
10+
],
11+
"scripts": {
12+
"dev": "docz dev",
13+
"build": "docz build",
14+
"serve": "docz serve"
15+
},
16+
"dependencies": {
17+
"docz": "next",
18+
"prop-types": "^15.7.2",
19+
"react": "^16.8.6",
20+
"react-dom": "^16.8.6",
21+
"scheduler": "^0.15.0"
22+
}
23+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react'
2+
import t from 'prop-types'
3+
4+
const kinds = {
5+
info: '#5352ED',
6+
positive: '#2ED573',
7+
negative: '#FF4757',
8+
warning: '#FFA502',
9+
}
10+
11+
const AlertStyled = ({ children, kind, ...rest }) => (
12+
<div
13+
style={{
14+
padding: 20,
15+
background: 'white',
16+
borderRadius: 3,
17+
color: 'white',
18+
background: kinds[kind],
19+
}}
20+
{...rest}
21+
>
22+
{children}
23+
</div>
24+
)
25+
26+
export const Alert = props => <AlertStyled {...props} />
27+
export default Alert
28+
Alert.propTypes = {
29+
/**
30+
* Used to set the color of the alert
31+
*/
32+
kind: t.oneOf(['info', 'positive', 'negative', 'warning']),
33+
}
34+
35+
Alert.defaultProps = {
36+
kind: 'info',
37+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
name: Alert
3+
menu: Components
4+
---
5+
6+
import { Playground, Props } from 'docz'
7+
// import Alert from 'components/Alert'
8+
import Alert from '@/Alert'
9+
10+
# Alert
11+
12+
## Properties
13+
14+
<Props of={Alert} />
15+
16+
## Basic usage
17+
18+
<Playground>
19+
<Alert>Some message</Alert>
20+
</Playground>
21+
22+
## Using different kinds
23+
24+
<Playground>
25+
<Alert kind="info">Some message</Alert>
26+
<Alert kind="positive">Some message</Alert>
27+
<Alert kind="negative">Some message</Alert>
28+
<Alert kind="warning">Some message</Alert>
29+
</Playground>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Getting Started
3+
route: /
4+
---
5+
6+
# Getting Started
7+
8+
Design systems enable teams to build better products faster by making design reusable—reusability makes scale possible. This is the heart and primary value of design systems. A design system is a collection of reusable components, guided by clear standards, that can be assembled together to build any number of applications.
9+
10+
Regardless of the technologies and tools behind them, a successful design system follows these guiding principles:
11+
12+
- **It’s consistent**. The way components are built and managed follows a predictable pattern.
13+
- **It’s self-contained**. Your design system is treated as a standalone dependency.
14+
- **It’s reusable**. You’ve built components so they can be reused in many contexts.
15+
- **It’s accessible**. Applications built with your design system are usable by as many people as possible, no matter how they access the web.
16+
- **It’s robust**. No matter the product or platform to which your design system is applied, it should perform with grace and minimal bugs.
17+
18+
## Consistency
19+
20+
Your first, most important task when starting out is to define the rules of your system, document them, and ensure that everyone follows them. When you have clearly documented code standards and best practices in place, designers and developers from across your organization can easily use and, more importantly, contribute to your design system.

0 commit comments

Comments
 (0)