Skip to content

Commit 6e12832

Browse files
erquhartKyleAMathews
authored andcommitted
fix netlify-cms and sass plugin css extraction (#4379)
1 parent 3da9f22 commit 6e12832

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

packages/gatsby-plugin-netlify-cms/src/gatsby-node.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const HtmlWebpackPlugin = require(`html-webpack-plugin`)
22
const ExtractTextPlugin = require(`extract-text-webpack-plugin`)
33

4+
const extractCmsCss = new ExtractTextPlugin(`cms.css`)
5+
46
function plugins(stage) {
57
const commonPlugins = [
68
// Output /admin/index.html
@@ -15,7 +17,7 @@ function plugins(stage) {
1517
case `develop`:
1618
return commonPlugins
1719
case `build-javascript`:
18-
return [...commonPlugins, new ExtractTextPlugin(`cms.css`)]
20+
return [...commonPlugins, extractCmsCss]
1921
default:
2022
return []
2123
}
@@ -52,7 +54,7 @@ function module(config, stage) {
5254
config.loader(`cms-css`, {
5355
test: /\.css$/,
5456
include: [/\/node_modules\/netlify-cms\//],
55-
loader: ExtractTextPlugin.extract([`css`]),
57+
loader: extractCmsCss.extract([`css`]),
5658
})
5759
return config
5860
default:

packages/gatsby-plugin-sass/src/__tests__/gatsby-node.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
describe(`gatsby-plugin-sass`, () => {
2-
jest.mock(`extract-text-webpack-plugin`, () => {
3-
return {
4-
extract(...args) {
5-
return { extractTextCalledWithArgs: args }
6-
},
2+
jest.mock(`extract-text-webpack-plugin`, () => class {
3+
extract(...args) {
4+
return { extractTextCalledWithArgs: args }
75
}
86
})
97

@@ -77,7 +75,7 @@ describe(`gatsby-plugin-sass`, () => {
7775
const stringified = JSON.stringify(options)
7876

7977
it(`modifies webpack config for ${stringified}`, () => {
80-
const config = { loader: jest.fn() }
78+
const config = { loader: jest.fn(), merge: jest.fn() }
8179
const modified = modifyWebpackConfig({ config, stage }, options)
8280

8381
expect(modified).toBe(config)

packages/gatsby-plugin-sass/src/gatsby-node.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const ExtractTextPlugin = require(`extract-text-webpack-plugin`)
22
const { cssModulesConfig } = require(`gatsby-1-config-css-modules`)
33

4+
const extractSass = new ExtractTextPlugin(`styles.css`, { allChunks: true })
5+
46
exports.modifyWebpackConfig = ({ config, stage }, options) => {
57
const sassFiles = /\.s[ac]ss$/
68
const sassModulesFiles = /\.module\.s[ac]ss$/
@@ -24,16 +26,21 @@ exports.modifyWebpackConfig = ({ config, stage }, options) => {
2426
config.loader(`sass`, {
2527
test: sassFiles,
2628
exclude: sassModulesFiles,
27-
loader: ExtractTextPlugin.extract([`css?minimize`, sassLoader]),
29+
loader: extractSass.extract([`css?minimize`, sassLoader]),
2830
})
2931

3032
config.loader(`sassModules`, {
3133
test: sassModulesFiles,
32-
loader: ExtractTextPlugin.extract(`style`, [
34+
loader: extractSass.extract(`style`, [
3335
cssModulesConfig(stage),
3436
sassLoader,
3537
]),
3638
})
39+
40+
config.merge({
41+
plugins: [extractSass],
42+
})
43+
3744
return config
3845
}
3946
case `develop-html`:
@@ -47,11 +54,16 @@ exports.modifyWebpackConfig = ({ config, stage }, options) => {
4754

4855
config.loader(`sassModules`, {
4956
test: sassModulesFiles,
50-
loader: ExtractTextPlugin.extract(`style`, [
57+
loader: extractSass.extract(`style`, [
5158
cssModulesConfig(stage),
5259
sassLoader,
5360
]),
5461
})
62+
63+
config.merge({
64+
plugins: [extractSass],
65+
})
66+
5567
return config
5668
}
5769
default: {

0 commit comments

Comments
 (0)