Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Add hot module reloading for theme and styles #1489

Merged
merged 79 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
04b81c3
make theme hmr loadable
elevatebart Dec 2, 2019
8432936
try making a theme hmr tool
Dec 4, 2019
5599ade
add an example for it
Dec 4, 2019
6a927f1
add styles in the mix
elevatebart Dec 5, 2019
7b30998
fix example
elevatebart Dec 5, 2019
93ab644
fix typings
elevatebart Dec 5, 2019
5fe0706
fix modulenamemapper fo jest tests
Dec 5, 2019
93e64c8
update snapshots
elevatebart Dec 6, 2019
17c3b92
Merge branch 'master' into feature-hmr-theme
elevatebart Dec 6, 2019
97ea3d0
Add tests for the new behavior
Dec 6, 2019
aa1468e
prevent eslint from being mean to jest mock
Dec 6, 2019
625a853
remove rsg styles type
elevatebart Dec 7, 2019
6bc462d
reorder imports
elevatebart Dec 7, 2019
0b8b0b4
make better tests
elevatebart Dec 7, 2019
c045116
make example filenames more explicit
elevatebart Dec 7, 2019
6988324
remove eslint exception in example
elevatebart Dec 7, 2019
baca15a
fix webpack and add comments
elevatebart Dec 7, 2019
db0dc70
update snapshots
elevatebart Dec 7, 2019
ad15b9e
add tests for make webpack config
elevatebart Dec 7, 2019
ffaa736
augment coverage over make-webpack-config
elevatebart Dec 8, 2019
2e59e7a
remove useless ependency
elevatebart Dec 8, 2019
f3491be
document styles and themes hmr
elevatebart Dec 8, 2019
cd2bfeb
fix typings
elevatebart Dec 8, 2019
dbf5d34
remove eslintrc changes
Dec 10, 2019
d040014
Merge branch 'master' into feature-hmr-theme
Dec 10, 2019
4efc09c
fix resolving of path from configDir
Dec 10, 2019
1956689
update docs and example
Dec 10, 2019
0d59a83
remove compile change
Dec 10, 2019
5304a02
make better style file path
Dec 10, 2019
25417e5
cookbook clarification
Dec 10, 2019
bb244ab
fix typings
elevatebart Dec 13, 2019
71c4368
Merge branch 'master' into feature-hmr-theme
elevatebart Dec 13, 2019
bd50c62
fix typo in docs
Dec 13, 2019
07bf941
Update case in the note docs
Dec 13, 2019
ee18773
remove added chevrons in cookbook
elevatebart Dec 15, 2019
57dfcd4
update examples package and lock
elevatebart Dec 15, 2019
b788d90
remove modifications from webpack config
elevatebart Dec 15, 2019
5cfd8a5
clean eslint changes
elevatebart Dec 22, 2019
d9d8c57
simplify themed example
elevatebart Dec 22, 2019
de03a30
fix redme for left button
elevatebart Dec 22, 2019
4057e1d
update themed
elevatebart Dec 23, 2019
921be72
improve types
elevatebart Dec 23, 2019
c21b266
use the styleguide-loader instead
elevatebart Dec 23, 2019
ae61ac3
remove all chanegs from make webpack config
elevatebart Dec 23, 2019
3d93261
make the HMR of theme work
elevatebart Dec 24, 2019
9bf7f84
optimize performance when not using style files
elevatebart Dec 24, 2019
e7eb6a0
rollback unwanted changes to eslint
elevatebart Dec 24, 2019
73fa018
update whitespace
elevatebart Dec 24, 2019
e872c99
replace tabs with spaces
elevatebart Dec 24, 2019
addc4cf
fix es5 export of styles and themes
elevatebart Dec 24, 2019
0cd3b36
update createssheet tests
elevatebart Dec 24, 2019
530c292
Merge branch 'master' into feature-hmr-theme
elevatebart Dec 24, 2019
df9122a
remove unwanted changes
elevatebart Dec 24, 2019
c0b9252
fix optimization
elevatebart Dec 24, 2019
6e055b9
add various comments
elevatebart Dec 24, 2019
1d75e27
add tests on styleguide-loader
elevatebart Dec 24, 2019
c7e66b4
more code coverage
elevatebart Dec 24, 2019
9a03e27
replace RE by regExp in tests
Dec 28, 2019
8b15b3e
complete the test clarification
elevatebart Dec 28, 2019
aca1c2b
remove custom state documentation
elevatebart Dec 28, 2019
a3c3e00
move all changes to styleguide-loader
elevatebart Dec 28, 2019
bc94634
avoid compiling test files
elevatebart Dec 28, 2019
80765a5
add comments regarding optimization
elevatebart Dec 28, 2019
a6dc174
fix tests and styleguide loader
elevatebart Dec 28, 2019
538f332
can't deal with default this way...
elevatebart Dec 28, 2019
d80ae8c
resolve es6 in loader side
elevatebart Dec 28, 2019
94e5e6a
ue has-sum intead of custom md5
elevatebart Dec 30, 2019
0978a5f
better case conventions for constants
elevatebart Dec 30, 2019
e9aa519
rename resolve esmodule
elevatebart Dec 30, 2019
e5ac083
fix typings
elevatebart Dec 30, 2019
419335f
rename es6 test file
elevatebart Jan 2, 2020
22eaedb
use destructured theme and styles
elevatebart Jan 2, 2020
fa6e2f2
Merge branch 'master' into feature-hmr-theme
elevatebart Jan 2, 2020
505bb5f
fix test name
elevatebart Jan 2, 2020
dd31dc9
fix types
elevatebart Jan 4, 2020
56ec459
remove hmrStyles
elevatebart Jan 4, 2020
c4ee026
update comments of styleguide-loader
elevatebart Jan 4, 2020
04a1d97
add comments and test
elevatebart Jan 4, 2020
ee94bec
update comments
elevatebart Jan 6, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -610,11 +610,11 @@ Folder for static HTML style guide generated with `styleguidist build` command.

#### `styles`

Type: `Object` or `Function`, optional
Type: `Object`, `String` or `Function`, optional

Customize styles of any Styleguidist’s component.
Customize styles of any Styleguidist’s component using an object, a function returning said object or a file path to a file exporting said styles.

See example in the [cookbook](Cookbook.md#how-to-change-styles-of-a-style-guide).
See examples in the [cookbook](Cookbook.md#how-to-change-styles-of-a-style-guide).

> **Note:** Using a function allows access to theme variables as seen in the example below. See available [theme variables](https://github.com/styleguidist/react-styleguidist/blob/master/src/client/styles/theme.ts). The returned object folows the same format as when configured as a litteral.

Expand All @@ -633,6 +633,8 @@ module.exports = {
}
```

**Note:** If using a file path, it has to be absolute or relative to the config file.

#### `template`

Type: `Object` or `Function`, optional.
Expand All @@ -653,16 +655,18 @@ A function that returns an HTML string, see [mini-html-webpack-plugin docs](http

#### `theme`

Type: `object`, optional
Type: `Object` or `String`, optional

Customize style guide UI fonts, colors, etc.
Customize style guide UI fonts, colors, etc. using a theme object or the path to a file exporting such object.

See example in the [cookbook](Cookbook.md#how-to-change-styles-of-a-style-guide).
The path is relative to the config file or absolute.

> **Note:** See available [theme variables](https://github.com/styleguidist/react-styleguidist/blob/master/src/client/styles/theme.ts).
See examples in the [cookbook](Cookbook.md#how-to-change-styles-of-a-style-guide).

> **Note:** See available [theme variables](https://github.com/styleguidist/react-styleguidist/blob/master/src/client/styles/theme.ts).
>
> **Note:** Styles use [JSS](https://github.com/cssinjs/jss/blob/master/docs/jss-syntax.md) with these plugins: [jss-plugin-isolate](https://github.com/cssinjs/jss/tree/master/packages/jss-plugin-isolate), [jss-plugin-nested](https://github.com/cssinjs/jss/tree/master/packages/jss-plugin-nested), [jss-plugin-camel-case](https://github.com/cssinjs/jss/tree/master/packages/jss-plugin-camel-case), [jss-plugin-default-unit](https://github.com/cssinjs/jss/tree/master/packages/jss-plugin-default-unit), [jss-plugin-compose](https://github.com/cssinjs/jss/tree/master/packages/jss-plugin-compose) and [jss-plugin-global](https://github.com/cssinjs/jss/tree/master/packages/jss-plugin-global).

>
> **Note:** Use [React Developer Tools](https://github.com/facebook/react) to find component and style names. For example a component `<LogoRenderer><h1 className="rsg--logo-53">` corresponds to an example above.

#### `title`
Expand Down Expand Up @@ -824,11 +828,11 @@ module.exports = {
```

> **Warning:** This option disables config load from `webpack.config.js`, load your config [manually](Webpack.md#reusing-your-projects-webpack-config).

>
> **Note:** `entry`, `externals`, `output`, `watch`, and `stats` options will be ignored. For production builds, `devtool` will also be ignored.

>
> **Note:** `CommonsChunkPlugins`, `HtmlWebpackPlugin`, `MiniHtmlWebpackPlugin`, `UglifyJsPlugin`, `TerserPlugin`, `HotModuleReplacementPlugin` plugins will be ignored because Styleguidist already includes them or they may break Styleguidist.

>
> **Note:** Run style guide in verbose mode to see the actual webpack config used by Styleguidist: `npx styleguidist server --verbose`.

See [Configuring webpack](Webpack.md) for examples.
65 changes: 57 additions & 8 deletions docs/Cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,56 @@ module.exports = {
> **Note:** Use [React Developer Tools](https://github.com/facebook/react) to find component and style names. For example a component `<LogoRenderer><h1 className="rsg--logo-53">` corresponds to an example above.
> **Note:** Use a function instead of an object for [styles](Configuration.md#styles) to access all heme variables in your custom styles.
> **Note:** Use a function instead of an object for [styles](Configuration.md#styles) to access all theme variables in your custom styles.
You can store all styles in a separate file to allow hot module replacement (HMR). Same goes for theme variables.

The same example above would then translate as:

In `styleguide.config,js`, objects are replaced with file paths

```javascript
module.exports = {
// ...
styles: './styleguide/styles.js',
theme: './styleguide/themes.js'
}
```

then in `./styleguide/theme.js`

```javascript
module.exports = {
color: {
link: 'firebrick',
linkHover: 'salmon'
},
fontFamily: {
base: '"Comic Sans MS", "Comic Sans", cursive'
}
}
```

and in `./styleguide/styles.js`

```javascript
module.exports = {
Logo: {
// We're changing the LogoRenderer component
logo: {
// We're changing the rsg--logo-XX class name inside the component
animation: 'blink ease-in-out 300ms infinite'
},
'@keyframes blink': {
to: { opacity: 0 }
}
}
}
```

Each modification of `theme.js` or `styles.js` will trigger a hot module replacement, updating the styleguide in the browser.

Check out the [themed example](https://github.com/styleguidist/react-styleguidist/tree/master/examples/themed) on the github repo to learn more and try it out.

```javascript
module.exports = {
Expand Down Expand Up @@ -406,16 +455,16 @@ module.exports = {

## How to debug my components and examples?

1. Open your browser’s developer tools
2. Write `debugger;` statement wherever you want: in a component source, a Markdown example or even in an editor in a browser.
1. Open your browser’s developer tools
2. Write `debugger;` statement wherever you want: in a component source, a Markdown example or even in an editor in a browser.

![](https://d3vv6lp55qjaqc.cloudfront.net/items/3i3E3j2h3t1315141k0o/debugging.png)

## How to debug the exceptions thrown from my components?

1. Put `debugger;` statement at the beginning of your code.
2. Press the ![Debugger](https://d3vv6lp55qjaqc.cloudfront.net/items/2h2q3N123N3G3R252o41/debugger.png) button in your browser’s developer tools.
3. Press the ![Continue](https://d3vv6lp55qjaqc.cloudfront.net/items/3b3c1P3g3O1h3q111I2l/continue.png) button and the debugger will stop execution at the next exception.
1. Put `debugger;` statement at the beginning of your code.
2. Press the ![Debugger](https://d3vv6lp55qjaqc.cloudfront.net/items/2h2q3N123N3G3R252o41/debugger.png) button in your browser’s developer tools.
3. Press the ![Continue](https://d3vv6lp55qjaqc.cloudfront.net/items/3b3c1P3g3O1h3q111I2l/continue.png) button and the debugger will stop execution at the next exception.

## How to use the production or development build of React?

Expand Down Expand Up @@ -461,9 +510,9 @@ devServer: {

Two options:

1. Put a `favicon.ico` file into the root folder of your site.
1. Put a `favicon.ico` file into the root folder of your site.

2. Use [template](Configuration.md#template) option:
2. Use [template](Configuration.md#template) option:

```javascript
module.exports = {
Expand Down
12 changes: 12 additions & 0 deletions examples/themed/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# React Styleguidist themed example style guide

How to start locally:

```
git clone https://github.com/styleguidist/react-styleguidist.git
cd react-styleguidist/examples/themed
npm install
npx styleguidist server
```

Then open [http://localhost:6060](http://localhost:6060) in your browser.
14 changes: 14 additions & 0 deletions examples/themed/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
presets: [
[
'@babel/env',
{
modules: false,
useBuiltIns: 'usage',
corejs: 3,
},
],
'@babel/react',
],
plugins: ['@babel/plugin-proposal-class-properties'],
};
Loading