You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add .eslintignore for test fixtures
The double quotes that the plugin adds go against the linting
config of the project, and editors that auto-fix linting rules
will try to convert quotes in `expected.js` files to single quotes,
causing tests to fail. It seems safest to ignore all fixture files
from linting.
* Allow createObjectExpression to take a boolean
* Allow getClassName to take an options argument
The only option is to silence styleName errors, for example in production.
If `silenceStyleNameErrors` is true, the styleNames which cannot be
found will simply be removed from the resulting classNames, matching
the behavior of `react-css-modules`.
This commit alone will not result in a change in behavior, the next
steps will be to pass in the option from the babel-plugin.
* Add `silenceStyleNameErrors` to options schema
* Pass silenceStyleNameErrors to getClassName
This hooks up the options set by the user into getClassName, so that it
has an effect. However, getClassName can also be used at runtime,
which this commit does not address.
* Provide silenceStyleNameErrors at runtime
This commit adds the options object for getClassName iif silenceStyleNameErrors
is true. By not always including the options object, it helps to save
a few characters in the generated code.
* Restructure Configuration docs
Seeing the flow types first thing in the Configuration section was
confusing to new users, so this adds a brief example of how to set
babel plugin options, and moves the flow types underneath the table
of options.
* Add silenceStyleNameErrors to README
* Loosen InputObjectType
Flow was already not happy with using `InputObjectType` within its own
definition, and was converting it to `{[key: string]: string | any}`
when I inspected it in Nuclide.
I’m honestly not sure how to specify a union type on an indexer as was
being attempted, because flow complains as soon as you try to provide
an object that has a property with a typed value.
* Allow more options to handle missing styleNames
This changes the option from a boolean “silenceStyleNameErrors” to an
enum “handleMissingStyleName” option, with possible values of “throw”
(default), “warn”, and “ignore”.
Copy file name to clipboardExpand all lines: README.md
+31-13
Original file line number
Diff line number
Diff line change
@@ -170,22 +170,21 @@ NODE_ENV=production ./test
170
170
171
171
## Configuration
172
172
173
-
```js
174
-
type FiletypeOptionsType = {|
175
-
+syntax: string,
176
-
+plugins?: $ReadOnlyArray<string>
177
-
|};
178
-
179
-
type FiletypesConfigurationType = {
180
-
[key: string]: FiletypeOptionsType
181
-
};
182
-
183
-
type GenerateScopedNameType= (localName:string, resourcePath:string) => string;
184
-
185
-
type GenerateScopedNameConfigurationType = GenerateScopedNameType | string;
173
+
Configure the options for the plugin within your `.babelrc` as follows:
174
+
175
+
```json
176
+
{
177
+
"plugins": [
178
+
["react-css-modules", {
179
+
"option": "value"
180
+
}]
181
+
]
182
+
}
186
183
187
184
```
188
185
186
+
### Options
187
+
189
188
|Name|Type|Description|Default|
190
189
|---|---|---|---|
191
190
|`context`|`string`|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()`|
@@ -194,12 +193,31 @@ type GenerateScopedNameConfigurationType = GenerateScopedNameType | string;
194
193
|`generateScopedName`|`?GenerateScopedNameConfigurationType`|Refer to [Generating scoped names](https://github.com/css-modules/postcss-modules#generating-scoped-names)|`[path]___[name]__[local]___[hash:base64:5]`|
195
194
|`removeImport`|`boolean`|Remove the matching style import. This option is used to enable server-side rendering.|`false`|
196
195
|`webpackHotModuleReloading`|`boolean`|Enables hot reloading of CSS in webpack|`false`|
196
+
|`handleMissingStyleName`|`"throw"`, `"warn"`, `"ignore"`|Determines what should be done for undefined CSS modules (using a `styleName` for which there is no CSS module defined). Setting this option to `"ignore"` is equivalent to setting `errorWhenNotFound: false` in [react-css-modules](https://github.com/gajus/react-css-modules#errorwhennotfound). |`"throw"`|
197
197
198
198
Missing a configuration? [Raise an issue](https://github.com/gajus/babel-plugin-react-css-modules/issues/new?title=New%20configuration:).
199
199
200
200
> Note:
201
201
> The default configuration should work out of the box with the [css-loader](https://github.com/webpack/css-loader).
202
202
203
+
#### Option types (flow)
204
+
205
+
```js
206
+
type FiletypeOptionsType = {|
207
+
+syntax: string,
208
+
+plugins?: $ReadOnlyArray<string>
209
+
|};
210
+
211
+
type FiletypesConfigurationType = {
212
+
[key: string]: FiletypeOptionsType
213
+
};
214
+
215
+
type GenerateScopedNameType= (localName:string, resourcePath:string) => string;
216
+
217
+
type GenerateScopedNameConfigurationType = GenerateScopedNameType | string;
218
+
219
+
```
220
+
203
221
### Configurate syntax loaders
204
222
205
223
To add support for different CSS syntaxes (e.g. SCSS), perform the following two steps:
0 commit comments