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

feat(cssSelectorPrefix): Add cssSelectorPrefix option #25

Merged
merged 2 commits into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
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