forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bundle Netlify CMS styles (gatsbyjs#3611)
* define webpack loader.exclude with array for extensibility * generate separate CSS bundle for Netlify CMS plugin
- Loading branch information
1 parent
53f66a4
commit d19ec31
Showing
2 changed files
with
63 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,70 @@ | ||
const HtmlWebpackPlugin = require(`html-webpack-plugin`) | ||
const HtmlWebpackIncludeAssetsPlugin = require(`html-webpack-include-assets-plugin`) | ||
const ExtractTextPlugin = require(`extract-text-webpack-plugin`) | ||
|
||
function plugins(stage) { | ||
const commonPlugins = [ | ||
// Output /admin/index.html | ||
new HtmlWebpackPlugin({ | ||
title: `Content Manager`, | ||
filename: `admin/index.html`, | ||
chunks: [`cms`], | ||
}), | ||
|
||
// Include the identity widget script in the html file | ||
new HtmlWebpackIncludeAssetsPlugin({ | ||
assets: [`https://identity.netlify.com/v1/netlify-identity-widget.js`], | ||
append: false, | ||
publicPath: false, | ||
}), | ||
] | ||
|
||
exports.modifyWebpackConfig = ( | ||
{ config, stage }, | ||
{ modulePath = `${__dirname}/cms.js` } | ||
) => { | ||
switch (stage) { | ||
case `develop`: | ||
return commonPlugins | ||
case `build-javascript`: | ||
return [...commonPlugins, new ExtractTextPlugin(`cms.css`)] | ||
default: | ||
return [] | ||
} | ||
} | ||
|
||
function module(config, stage) { | ||
switch (stage) { | ||
case `build-javascript`: | ||
config.merge({ | ||
entry: { | ||
cms: modulePath, | ||
}, | ||
plugins: [ | ||
new HtmlWebpackPlugin({ | ||
title: `Content Manager`, | ||
filename: `admin/index.html`, | ||
chunks: [`cms`], | ||
}), | ||
new HtmlWebpackIncludeAssetsPlugin({ | ||
assets: [ | ||
`https://identity.netlify.com/v1/netlify-identity-widget.js`, | ||
], | ||
append: false, | ||
publicPath: false, | ||
}), | ||
], | ||
// Exclude Netlify CMS styles from Gatsby CSS bundle. This relies on | ||
// Gatsby using webpack-configurator for webpack config extension, and | ||
// also on the target loader key being named "css" in Gatsby's webpack | ||
// config. | ||
config.loader(`css`, { | ||
exclude: [/\/node_modules\/netlify-cms\//], | ||
}) | ||
|
||
// Exclusively extract Netlify CMS styles to /cms.css (filename configured | ||
// above with plugin instantiation). | ||
config.loader(`cms-css`, { | ||
test: /\.css$/, | ||
include: [/\/node_modules\/netlify-cms\//], | ||
loader: ExtractTextPlugin.extract([`css`]), | ||
}) | ||
return config | ||
default: | ||
return config | ||
} | ||
} | ||
|
||
exports.modifyWebpackConfig = ( | ||
{ config, stage }, | ||
{ modulePath = `${__dirname}/cms.js` } | ||
) => { | ||
config.merge({ | ||
entry: { | ||
cms: modulePath, | ||
}, | ||
plugins: plugins(stage), | ||
}) | ||
|
||
module(config, stage) | ||
|
||
return config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters