Skip to content

Commit acbb2e8

Browse files
committed
fix: make context value configurable (fixes #33)
1 parent e58df31 commit acbb2e8

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ NODE_ENV=production ./test
168168
|Name|Description|Default|
169169
|---|---|---|
170170
|`generateScopedName`|Refer to [Generating scoped names](https://github.com/css-modules/postcss-modules#generating-scoped-names)|`[path]___[name]__[local]___[hash:base64:5]`|
171+
|`context`|Must match webpack [`context`](https://webpack.github.io/docs/configuration.html#context) configuration. [`css-loader`](https://github.com/webpack/css-loader) inherits `context` values from webpack. Other CSS module implementations might use different context resolution logic.|`process.cwd()`|
171172

172173
Missing a configuration? [Raise an issue](https://github.com/gajus/babel-plugin-react-css-modules/issues/new?title=New%20configuration:).
173174

src/requireCssModule.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,17 @@ const getTokens = (runner, cssSourceFilePath: string): StyleModuleMapType => {
4444
};
4545

4646
type OptionsType = {|
47-
generateScopedName?: string
47+
generateScopedName?: string,
48+
context?: string
4849
|};
4950

5051
export default (cssSourceFilePath: string, options: OptionsType): StyleModuleMapType => {
5152
// eslint-disable-next-line prefer-const
5253
let runner;
5354

54-
const scopedName = genericNames(options.generateScopedName || '[path]___[name]__[local]___[hash:base64:5]');
55+
const scopedName = genericNames(options.generateScopedName || '[path]___[name]__[local]___[hash:base64:5]', {
56+
context: options.context || process.cwd()
57+
});
5558

5659
const fetch = (to: string, from: string) => {
5760
const fromDirectoryPath = dirname(from);

0 commit comments

Comments
 (0)