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

fix(gatsby-plugin-postcss): Always ensure postcss.config.js is loaded #16521

Merged
merged 3 commits into from
Aug 13, 2019
Merged
Changes from 1 commit
Commits
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: 8 additions & 26 deletions packages/gatsby-plugin-postcss/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,6 @@ import resolve from "./resolve"
const CSS_PATTERN = /\.css$/
const MODULE_CSS_PATTERN = /\.module\.css$/

const getOptions = pluginOptions => {
const options = { ...pluginOptions }

delete options.plugins

const postcssPlugins = options.postCssPlugins

if (postcssPlugins) {
options.plugins = postcssPlugins
}

delete options.postCssPlugins

return options
}

const isCssRules = rule =>
rule.test &&
(rule.test.toString() === CSS_PATTERN.toString() ||
Expand All @@ -31,20 +15,18 @@ const findCssRules = config =>

exports.onCreateWebpackConfig = (
{ actions, stage, loaders, getConfig },
pluginOptions
{ cssLoaderOptions = {}, postCssPlugins, ...postcssOptions }
) => {
const isProduction = !stage.includes(`develop`)
const isSSR = stage.includes(`html`)
const config = getConfig()
const cssRules = findCssRules(config)
const postcssOptions = getOptions(pluginOptions)

const generateCssLoaderOptions = options =>
Object.assign(
{ importLoaders: 1 },
options,
pluginOptions.cssLoaderOptions || {}
)
delete postcssOptions.plugins

if (postCssPlugins) {
postcssOptions.plugins = postCssPlugins
}

const postcssLoader = {
loader: resolve(`postcss-loader`),
Expand All @@ -54,12 +36,12 @@ exports.onCreateWebpackConfig = (
test: CSS_PATTERN,
use: isSSR
? [loaders.null()]
: [loaders.css(generateCssLoaderOptions()), postcssLoader],
: [loaders.css({ ...cssLoaderOptions, importLoaders: 1 }), postcssLoader],
}
const postcssRuleModules = {
test: MODULE_CSS_PATTERN,
use: [
loaders.css(generateCssLoaderOptions({ modules: true })),
loaders.css({ ...cssLoaderOptions, importLoaders: 1, modules: true }),
postcssLoader,
],
}
Expand Down