Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
docs: add webpack alias example
Browse files Browse the repository at this point in the history
  • Loading branch information
rakannimer committed Nov 1, 2019
1 parent 334cb10 commit da5ccd6
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/webpack-alias/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.docz
node_modules
67 changes: 67 additions & 0 deletions examples/webpack-alias/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Docz example with webpack aliases

## Using `create-docz-app`

```sh
npx create-docz-app docz-app-webpack-alias --example webpack-alias
# or
yarn create docz-app docz-app-webpack-alias --example webpack-alias
```

## Download manually

```sh
curl https://codeload.github.com/doczjs/docz/tar.gz/master | tar -xz --strip=2 docz-master/examples/webpack-alias
mv webpack-alias docz-webpack-alias-example
cd docz-webpack-alias-example
```

## Notes

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/

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'`.

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'`.

```js
// gatsby-node.js
const path = require('path')

exports.onCreateWebpackConfig = args => {
args.actions.setWebpackConfig({
resolve: {
// Note the '..' in the path because the docz gatsby project lives in the `.docz` directory
modules: [path.resolve(__dirname, '../src'), 'node_modules'],
alias: {
'@': path.resolve(__dirname, '../src/components/'),
},
},
})
}

```

## Setup

```sh
yarn # npm i
```

## Run

```sh
yarn dev # npm run dev
```

## Build

```sh
yarn build # npm run build
```

## Serve built app

```sh
yarn serve # npm run serve
```
3 changes: 3 additions & 0 deletions examples/webpack-alias/doczrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
menu: ['Getting Started', 'Components'],
}
12 changes: 12 additions & 0 deletions examples/webpack-alias/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const path = require('path')

exports.onCreateWebpackConfig = args => {
args.actions.setWebpackConfig({
resolve: {
modules: [path.resolve(__dirname, '../src'), 'node_modules'],
alias: {
'@': path.resolve(__dirname, '../src/components/'),
},
},
})
}
23 changes: 23 additions & 0 deletions examples/webpack-alias/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "docz-example-basic",
"private": true,
"version": "2.0.0-rc.41",
"license": "MIT",
"files": [
"src/",
"doczrc.js",
"package.json"
],
"scripts": {
"dev": "docz dev",
"build": "docz build",
"serve": "docz serve"
},
"dependencies": {
"docz": "next",
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"scheduler": "^0.15.0"
}
}
37 changes: 37 additions & 0 deletions examples/webpack-alias/src/components/Alert.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react'
import t from 'prop-types'

const kinds = {
info: '#5352ED',
positive: '#2ED573',
negative: '#FF4757',
warning: '#FFA502',
}

const AlertStyled = ({ children, kind, ...rest }) => (
<div
style={{
padding: 20,
background: 'white',
borderRadius: 3,
color: 'white',
background: kinds[kind],
}}
{...rest}
>
{children}
</div>
)

export const Alert = props => <AlertStyled {...props} />
export default Alert
Alert.propTypes = {
/**
* Used to set the color of the alert
*/
kind: t.oneOf(['info', 'positive', 'negative', 'warning']),
}

Alert.defaultProps = {
kind: 'info',
}
29 changes: 29 additions & 0 deletions examples/webpack-alias/src/components/Alert.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: Alert
menu: Components
---

import { Playground, Props } from 'docz'
// import Alert from 'components/Alert'
import Alert from '@/Alert'

# Alert

## Properties

<Props of={Alert} />

## Basic usage

<Playground>
<Alert>Some message</Alert>
</Playground>

## Using different kinds

<Playground>
<Alert kind="info">Some message</Alert>
<Alert kind="positive">Some message</Alert>
<Alert kind="negative">Some message</Alert>
<Alert kind="warning">Some message</Alert>
</Playground>
20 changes: 20 additions & 0 deletions examples/webpack-alias/src/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Getting Started
route: /
---

# Getting Started

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.

Regardless of the technologies and tools behind them, a successful design system follows these guiding principles:

- **It’s consistent**. The way components are built and managed follows a predictable pattern.
- **It’s self-contained**. Your design system is treated as a standalone dependency.
- **It’s reusable**. You’ve built components so they can be reused in many contexts.
- **It’s accessible**. Applications built with your design system are usable by as many people as possible, no matter how they access the web.
- **It’s robust**. No matter the product or platform to which your design system is applied, it should perform with grace and minimal bugs.

## Consistency

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 comments on commit da5ccd6

Please sign in to comment.