Skip to content

Commit fe44967

Browse files
authored
Add back deleted docs (#171)
1 parent 4fb5511 commit fe44967

File tree

4 files changed

+184
-0
lines changed

4 files changed

+184
-0
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
---
2+
title: CSS Modules
3+
path: /css-modules/
4+
---
5+
6+
# CSS Modules
7+
8+
## Setup
9+
10+
```
11+
yarn add --dev gulp gulp-postcss autoprefixer cssnano postcss-modules gulp-concat gulp-remember
12+
```
13+
14+
```js
15+
// gulpfile.js
16+
17+
const fs = require("fs");
18+
const path = require("path");
19+
const { src, dest, task, watch, lastRun, parallel } = require("gulp");
20+
const postcss = require("gulp-postcss");
21+
const autoprefixer = require("autoprefixer");
22+
const cssnano = require("cssnano");
23+
const modules = require("postcss-modules");
24+
const concat = require("gulp-concat");
25+
const remember = require("gulp-remember");
26+
27+
function css() {
28+
return src(["**.css"], { sourcemaps: true, since: lastRun(css) })
29+
.pipe(postcss([modules(), autoprefixer()]))
30+
.pipe(remember("css"))
31+
.pipe(concat("styles.css"))
32+
.pipe(postcss([cssnano()]))
33+
.pipe(dest("src/static", { sourcemaps: true }));
34+
}
35+
36+
function watchCss() {
37+
const watcher = watch("**.css", css);
38+
watcher.on("change", file => {
39+
remember.forget("css", path.join(process.cwd(), file));
40+
});
41+
watcher.on("unlink", file => {
42+
fs.unlink(`${file}.json`, err => {});
43+
});
44+
}
45+
46+
exports.build = css;
47+
exports.default = parallel(css, watchCss);
48+
49+
```
50+
51+
Gulp usage:
52+
53+
```
54+
# To build and watch rebuild CSS
55+
gulp
56+
57+
# To just build CSS
58+
gulp build
59+
```
60+
61+
62+
### npm scripts
63+
64+
**Update your build command**
65+
66+
```json
67+
{
68+
"scripts": {
69+
"build-production": "gulp build && fusion build --production"
70+
}
71+
}
72+
```
73+
74+
**Updating your dev command**
75+
```
76+
yarn add concurrently --dev
77+
```
78+
79+
```json
80+
{
81+
"scripts": {
82+
"dev": "concurrently gulp 'fusion dev'"
83+
}
84+
}
85+
```
86+
87+
## Usage
88+
89+
```
90+
src/
91+
├── components/
92+
│ ├── foo.js
93+
│ ├── foo.css
94+
│ └── foo.css.json (generated)
95+
└── static/
96+
└── styles.css (generated)
97+
```
98+
99+
### Using CSS modules in components
100+
101+
```css
102+
// foo.css
103+
104+
.bar {
105+
color: red;
106+
}
107+
108+
.baz {
109+
color: green;
110+
}
111+
```
112+
113+
```jsx
114+
// foo.js
115+
116+
import styles from "./foo.css.json";
117+
118+
export const Foo = () => {
119+
return (
120+
<div className={styles.bar}>
121+
<div className={styles.baz} />
122+
</div>
123+
);
124+
};
125+
```
126+
127+
### Adding bundled CSS to the page
128+
129+
```jsx
130+
// In root component
131+
132+
import { assetUrl } from "fusion-core";
133+
import { Helmet } from "fusion-plugin-react-helmet-async";
134+
135+
const css = assetUrl("../static/styles.css");
136+
137+
const app = (
138+
<App>
139+
<Helmet>
140+
<link rel="stylesheet" href={css} />
141+
</Helmet>
142+
</App>
143+
);
144+
```

documentation/docs/references/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ This section contains articles that deep dive into specific parts of Fusion.js.
1818
- [Security](/docs/references/security)
1919
- [Typing](/docs/references/typing)
2020
- [Universal Rendering](/docs/references/universal-rendering)
21+
- [SVG React components](/docs/references/svg-react-components)
22+
- [CSS Modules](/docs/references/css-modules)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: SVG React Components
3+
path: /svg-react-components/
4+
---
5+
6+
# SVG React Components
7+
8+
React components can be generated from SVG files using [https://github.com/smooth-code/svgr](https://github.com/smooth-code/svgr).
9+
10+
Suppose you have the following icons:
11+
12+
```
13+
src/
14+
└── icons
15+
├── foo.svg
16+
└── bar.svg
17+
```
18+
19+
Running `npx @svgr/cli -d src/icons src/icons` will generate the corresponding React components:
20+
21+
```
22+
src/
23+
└── icons
24+
├── foo.svg
25+
├── foo.js
26+
├── bar.svg
27+
└── bar.js
28+
```
29+
30+
These can be imported:
31+
32+
```js
33+
import Foo from "./foo.js";
34+
```

src/nav-docs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,7 @@ children:
105105
path: '/typing'
106106
- title: 'Universal rendering'
107107
path: '/universal-rendering'
108+
- title: 'SVG React components'
109+
path: '/svg-react-components'
110+
- title: 'CSS Modules'
111+
path: '/css-modules'

0 commit comments

Comments
 (0)