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

Sandboxed code examples #649

Merged
merged 30 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
724e44c
add iframe component
shawnbot Jan 15, 2019
d43d827
move global prism styles out of _app
shawnbot Jan 15, 2019
395cbe6
add CommonStyles and CommonScripts exports
shawnbot Jan 15, 2019
0ffbad2
move prism styles, add frames to examples
shawnbot Jan 15, 2019
19f8856
use CommonScripts and CommonStyles
shawnbot Jan 15, 2019
48463bd
sort imports, comment out ERB transform
shawnbot Jan 15, 2019
4814513
docs: tidy up rgb() guidance
shawnbot Jan 15, 2019
209bef3
move prism-github import back to _app
shawnbot Jan 15, 2019
3074c9e
fix: load static primer.css in production
shawnbot Jan 15, 2019
411df2a
nix @zeit/next-css
shawnbot Jan 15, 2019
05079b2
move prism-github import back
shawnbot Jan 15, 2019
a5b66d9
nix primer.css build from CommonStyles
shawnbot Jan 15, 2019
6bb3df9
use <Head/> to get imported styles
shawnbot Jan 15, 2019
51dbf9a
nix prebuild script
shawnbot Jan 15, 2019
87aaf87
do css links the right way?
shawnbot Jan 15, 2019
d836921
nix DocumentContext
shawnbot Jan 16, 2019
64ab348
don't use webpack to alias primer css in production
shawnbot Jan 16, 2019
0e2b6a4
mark HTML principles examples as dead/inert
shawnbot Jan 16, 2019
a31da09
bump to @primer/components v8.2.0
shawnbot Jan 16, 2019
ae09f2a
pass document files context via <body data-files>
shawnbot Jan 16, 2019
92b5f6a
tidy up markdown.js
shawnbot Jan 16, 2019
85d6383
attempt to resize Frame components dynamically
shawnbot Jan 16, 2019
b147876
rework CodeExample structure a bit
shawnbot Jan 16, 2019
e41bfdd
bring back @zeit/next-css
shawnbot Jan 16, 2019
d93360b
try reusing @zeit/next-css loader directly
shawnbot Jan 17, 2019
b56cd2b
move redirect out or utils.js
shawnbot Jan 17, 2019
20dd7c1
fix landing page meta-package styles
shawnbot Jan 17, 2019
8898fa3
lint whitespace
shawnbot Jan 17, 2019
78d0e46
lint pages/_document.js
shawnbot Jan 17, 2019
5c653f0
lint
shawnbot Jan 17, 2019
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
34 changes: 18 additions & 16 deletions docs/lib/config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable no-console */
const sync = require('./sync')
const cssLoaderConfig = require('@zeit/next-css/css-loader-config')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so for some reason I wasn't able to use the @zeit/next-css "plugin", but their "loader config" works? ¯\_(ツ)_/¯

const {CI, NODE_ENV, NOW_URL} = process.env

const PRIMER_SCSS = 'primer/index.scss$'
const PRIMER_STATIC_CSS = require.resolve('primer/build/build.css')

module.exports = (nextConfig = {}) => {
const {assetPrefix = NOW_URL || ''} = nextConfig

Expand All @@ -26,13 +24,29 @@ module.exports = (nextConfig = {}) => {
)
}

const {dev} = options
const {dev, isServer} = options

// only attempt to sync locally and in CI
if (dev && !configured) {
sync({watch: !CI})
}

// in production, we don't need to compile Primer from SCSS; just inline
// the CSS build!
if (!dev) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way things are set up now, we only need the CSS loader (as opposed to Sass) in production. In fact, the Sass loader doesn't work in production because the Primer CSS modules aren't hoisted such that they all live in node_modules. This is a problem that will go away once we collapse the monorepo.

config.resolve.alias['primer/index.scss$'] = require.resolve('primer/build/build.css')

const cssLoader = cssLoaderConfig(config, {
dev,
isServer
})
options.defaultLoaders.css = cssLoader
config.module.rules.push({
test: /\.css$/,
loader: cssLoader
})
}

config.module.rules.push({
test: /\.svg$/,
use: '@svgr/webpack'
Expand All @@ -46,18 +60,6 @@ module.exports = (nextConfig = {}) => {
]
})

/**
* in production we don't have access to ../modules, so we need to
* rewrite the 'primer/index.scss' import to the static CSS build
*/
if (!dev) {
config.resolve.alias[PRIMER_SCSS] = PRIMER_STATIC_CSS
// only log the aliasing once
if (!configured) {
console.warn(`*** rewriting ${PRIMER_SCSS} to ${PRIMER_STATIC_CSS}`)
}
}

configured = true
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options)
Expand Down
20 changes: 9 additions & 11 deletions docs/next.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
const {join, resolve} = require('path')
const css = require('@zeit/next-css')
const sass = require('@zeit/next-sass')
const withSass = require('@zeit/next-sass')
const configure = require('./lib/config')

module.exports = configure(
css(
sass({
sassLoaderOptions: {
includePaths: [
resolve(__dirname, '../modules')
]
}
})
)
withSass({
sassLoaderOptions: {
includePaths: [
resolve(__dirname, '../modules'),
resolve(__dirname, 'node_modules')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary to resolve the CSS build in production.

]
}
})
)
Loading