-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Changes from 25 commits
724e44c
d43d827
395cbe6
0ffbad2
19f8856
48463bd
4814513
209bef3
3074c9e
411df2a
05079b2
a5b66d9
6bb3df9
51dbf9a
87aaf87
d836921
64ab348
0e2b6a4
a31da09
ae09f2a
92b5f6a
85d6383
b147876
e41bfdd
d93360b
b56cd2b
20dd7c1
8898fa3
78d0e46
5c653f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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') | ||
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 | ||
|
||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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' | ||
|
@@ -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) | ||
|
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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is necessary to resolve the CSS build in production. |
||
] | ||
} | ||
}) | ||
) |
There was a problem hiding this comment.
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? ¯\_(ツ)_/¯