Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
feat(cssSelectorPrefix): Add cssSelectorPrefix option (#25)
Browse files Browse the repository at this point in the history
* feat(cssSelectorPrefix): Add cssSelectorPrefix to support standalone style guide header & footer

* WIP: Updated readme with usage of cssSelectorPrefix
  • Loading branch information
dborysiewicz committed Oct 26, 2017
1 parent 02489d1 commit cb00500
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ module.exports = decorateClientConfig(config, {
});
```

### CSS Selector Prefix

This selector prefix is automatically prepended to all selectors to ensure styles don't leak out into the global scope.
For example, this is used for generating the standalone header & footer in the style guide.

```js
module.exports = decorateClientConfig(config, {
cssSelectorPrefix: '.__SSG__'
});
```

## Contributing

Refer to [CONTRIBUTING.md](./CONTRIBUTING.md).
Expand Down
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ const decorateServerConfig = (config, options) => {
});
}

const postcssPlugins = ({ cssSelectorPrefix }, autoprefixerConfig) =>
[require('autoprefixer')(autoprefixerConfig)]
.concat(!cssSelectorPrefix ? [] : [
require('postcss-prefix-selector')({
prefix: `:global(${cssSelectorPrefix})`
})
]);

const decorateClientConfig = (config, options) => {
const extractTextPlugin = options && options.extractTextPlugin;
const { absolute } = getIncludePaths(options);
Expand Down Expand Up @@ -258,7 +266,7 @@ const decorateClientConfig = (config, options) => {
{
loader: require.resolve('postcss-loader'),
options: {
plugins: () => [require('autoprefixer')(autoprefixerConfig)]
plugins: () => postcssPlugins(options)
}
},
require.resolve('less-loader')
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"less": "^2.7.2",
"less-loader": "^4.0.5",
"postcss-loader": "^2.0.7",
"postcss-prefix-selector": "^1.6.0",
"raw-loader": "^0.5.1",
"style-loader": "^0.19.0",
"svgo-loader": "^1.2.1",
Expand Down

0 comments on commit cb00500

Please sign in to comment.