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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back Primer CSS build and instructions for using it #260

Merged
merged 55 commits into from Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
3915a94
nix now from dev deps; move primer-* to deps
shawnbot Sep 11, 2018
73cd097
Merge branch 'master' into base-css
shawnbot Sep 14, 2018
7020979
add BaseCSS component, macros babel plugin
shawnbot Sep 14, 2018
dd66ee5
install babel-plugin-macros and preval
shawnbot Sep 14, 2018
0c3fed3
add primer-tables
shawnbot Sep 14, 2018
3cbc134
update package-lock
shawnbot Sep 14, 2018
d7caa48
build base CSS statically post-dist
shawnbot Sep 14, 2018
4a0ae59
import primer-tables in base styles
shawnbot Sep 14, 2018
ab017c1
render BaseCSS *and* styled-components statically
shawnbot Sep 14, 2018
53c3879
don't import primer-react.css in _app.js
shawnbot Sep 14, 2018
cf319ca
remove next-sass from next.config.js
shawnbot Sep 14, 2018
805c3f3
uninstall @zeit/next-sass
shawnbot Sep 14, 2018
1a3513b
export css from BaseCSS, allow children
shawnbot Sep 14, 2018
92975e4
add basic BaseCSS tests
shawnbot Sep 14, 2018
b549245
lint
shawnbot Sep 14, 2018
74a8204
[skip ci] update styling docs
shawnbot Sep 14, 2018
0231d95
simplify base css output
shawnbot Sep 14, 2018
e0d84c1
simplify BaseCSS <style> tag, `css` property
shawnbot Sep 14, 2018
0797898
update BaseCSS tests
shawnbot Sep 14, 2018
3deed4b
[skip ci] update BaseCSS.css usage instructions
shawnbot Sep 14, 2018
a4853aa
prefer <head> for critical CSS
shawnbot Sep 14, 2018
4eea3d6
update BaseCSS usage instructions
shawnbot Sep 14, 2018
9e844d4
move BaseCSS to import from 'primer-react/css'
shawnbot Sep 14, 2018
0fa0e88
add css.js to now deployments
shawnbot Sep 14, 2018
d0ffb66
update styled-system and system-components
shawnbot Sep 17, 2018
a21a4d5
update test snapshots with new styled-system
shawnbot Sep 17, 2018
ddb60a5
better styling docs
shawnbot Sep 19, 2018
5a8793f
better flesh out CSS for fully static sites
shawnbot Sep 19, 2018
f14fb08
set uglifyOptions.mangle = false in webpack config
shawnbot Sep 17, 2018
3a311c7
nix kit
shawnbot Sep 17, 2018
707c94b
try more granular keep_fnames again
shawnbot Sep 17, 2018
4437593
update version
Sep 18, 2018
8e6310a
regenerate package-lock.json
shawnbot Sep 19, 2018
46e5b09
Merge remote-tracking branch 'origin/q3-lochness-monster' into base-css
shawnbot Sep 19, 2018
dc6daec
add node-sass to devDeps
shawnbot Sep 19, 2018
8b84984
rename primer-react.scss -> primer-components.scss
shawnbot Sep 19, 2018
296ebf4
nix css.js and BaseCSS component
shawnbot Sep 19, 2018
f0656ef
nix babel-plugin-macros
shawnbot Sep 19, 2018
d90a682
add raw-loader for *.css imports
shawnbot Sep 19, 2018
b6b3f85
import base CSS from the built file
shawnbot Sep 19, 2018
a5d1668
update required and missing files in npm-pack-check
shawnbot Sep 19, 2018
08d9334
rebuild package-lock.json
shawnbot Sep 19, 2018
2420a2d
add dist:css run-script, do it postdist + prebuild
shawnbot Sep 19, 2018
a5584c7
nix css.js from now.json files list
shawnbot Sep 19, 2018
19a7f6a
Update docs for importing base CSS
shawnbot Sep 19, 2018
5c2b241
remove reference to BaseCSS
shawnbot Sep 19, 2018
d043877
Restructure styling sections, rewrite static CSS docs
shawnbot Sep 19, 2018
513c3fe
run dist:css before dev
shawnbot Sep 19, 2018
70094e9
tweak comment
shawnbot Sep 19, 2018
28c4f1d
move primer-* css modules to devDependencies
shawnbot Sep 19, 2018
d924008
nix primer-tables, revive border-collapse
shawnbot Sep 19, 2018
89de94d
nix system-classnames (unused)
shawnbot Sep 19, 2018
78e6f87
move emotion-theming and emotion-server to dev
shawnbot Sep 19, 2018
48de21f
update package-lock.json
shawnbot Sep 19, 2018
d6085c9
move primer-utilities to devDependencies
shawnbot Sep 20, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
77 changes: 66 additions & 11 deletions README.md
Expand Up @@ -33,22 +33,75 @@ import {

### Styling

This project uses [emotion] under the hood to generate static CSS from _some_ component styles, but still relies on [Primer CSS] for some component styles that haven't yet been ported over.
This project uses [emotion] to generate static CSS for most component styles, but still relies on [Primer CSS] for some classname-based styles that haven't yet been ported over.

To ensure proper styling, you'll need to link to the most recent build of [Primer CSS] in one of the following ways:
To ensure proper styling of all Primer components, you'll need to include some static CSS that's distributed with the `@primer/components` npm package in `dist/primer-components.css`.

1. If you're using webpack, you can install [style-loader](https://github.com/webpack-contrib/style-loader) and [css-loader](), `import 'primer/build/build.css'` in your bundle, and include the following in your webpack config's `module.rules` list:
#### JavaScript bundlers
If you're using a JavaScript bundler that supports CSS imports, you can import it in your bundles directly:

```js
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
```
```js
import '@primer/components/dist/css/build.css'
```

If you're using webpack, you will need to install [style-loader](https://github.com/webpack-contrib/style-loader) and configure webpack to use it for imports ending in '.css', e.g.

```js
{
module: {
rules: [
{
test: /\.css$/,
use: 'style-loader'
}
]
}
}
```

#### Server inlining
If you run a Node server, you can read the file from disk at startup:

```jsx
const {readFileSync} = require('fs')
const cssPath = require.resolve('@primer/components/dist/primer-components.css')
const css = readFileSync(cssPath, 'utf8')
```

Then, inline it into the `<head>` of your HTML template(s) or render it server-side in React like so:

```jsx
// assuming the `css` variable is set as above
export default () => (
<html>
<head>
<style>{css}</style>
</head>
<body>
...
</body>
</html>
)
```

#### Static apps
For fully static or statically generated (Jekyll, Hugo, etc.) apps, you may need to manually copy `node_modules/@primer/components/dist/css/build.css` (after `npm install --save @primer/components`) to one of your site's public directories, i.e. `/assets`:

```sh
cp node_modules/@primer/components/dist/css/build.css assets/primer-components.css
```

Then link to it in the `<head>` of your HTML document(s):

```html
<link rel="stylesheet" href="/assets/primer-components.css">
```

### Static CSS rendering

1. **For pre-production applications**, you can link directly to [the build on unpkg.com](https://unpkg.com/primer/build/build.css).
Some Primer components rendered client-side may produce a [flash of unstyled content]. You can avoid most jarring flashes by ensuring that `primer-components.css` is either inlined or linked in the `<head>` of your document with one of the techniques described above.

1. Otherwise, you can `npm install --save primer` and either or link `node_modules/primer/build/build.css` to your source directory.
If you're rendering React components both server-side _and_ client-side, we suggest following [Emotion's server-side rendering instructions](https://emotion.sh/docs/ssr) to avoid the flash of unstyled content for server-rendered components. This repo's [documentation template component](https://github.com/primer/components/blob/master/pages/_document.js) demonstrates how to do this in [Next.js].

## Local Development

Expand All @@ -73,3 +126,5 @@ To run `primer-react` locally when adding or updating components:

[emotion]: https://emotion.sh/
[Primer CSS]: https://github.com/primer/primer
[flash of unstyled content]: https://en.wikipedia.org/wiki/Flash_of_unstyled_content
[Next.js]: https://github.com/zeit/next.js
13 changes: 10 additions & 3 deletions next.config.js
@@ -1,8 +1,9 @@
const withPlugins = require('next-compose-plugins')
const sass = require('@zeit/next-sass')
const mdx = require('@zeit/next-mdx')({extension: /\.mdx?$/})
const mdx = require('@zeit/next-mdx')

module.exports = withPlugins([sass, mdx], {
module.exports = withPlugins([
mdx({extension: /\.mdx?$/})
], {
/*
* Note: Prefixing assets with the fully qualified deployment URL
* makes them available even when the site is served from a path alias, as in
Expand All @@ -15,6 +16,12 @@ module.exports = withPlugins([sass, mdx], {
},

webpack(config, {dev}) {
// load primer-components.css as raw string
config.module.rules.push({
test: /\.css$/,
use: 'raw-loader'
})

// we only care about disabling mangling in production
if (dev) {
return config
Expand Down