1 | export function shouldCssModules(options) {
|
2 | const passedInOption = processCssmodulesArgument(options);
|
3 |
|
4 |
|
5 | const moduleAllCss = passedInOption === true;
|
6 |
|
7 |
|
8 | const allowOnlySuffixModule = passedInOption === null;
|
9 |
|
10 | return moduleAllCss || allowOnlySuffixModule;
|
11 | }
|
12 |
|
13 | export function cssModulesConfig(options) {
|
14 | const passedInOption = processCssmodulesArgument(options);
|
15 | const isWatchMode = options.watch;
|
16 | const hasPassedInScopeName = !(
|
17 | typeof passedInOption === 'boolean' || passedInOption === null
|
18 | );
|
19 |
|
20 | if (shouldCssModules(options) || hasPassedInScopeName) {
|
21 | let generateScopedName = isWatchMode
|
22 | ? '_[name]__[local]__[hash:base64:5]'
|
23 | : '_[hash:base64:5]';
|
24 |
|
25 | if (hasPassedInScopeName) {
|
26 | generateScopedName = passedInOption;
|
27 | }
|
28 |
|
29 | return { generateScopedName };
|
30 | }
|
31 |
|
32 | return false;
|
33 | }
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | function processCssmodulesArgument(options) {
|
41 | if (options['css-modules'] === 'true' || options['css-modules'] === true)
|
42 | return true;
|
43 | if (options['css-modules'] === 'false' || options['css-modules'] === false)
|
44 | return false;
|
45 | if (options['css-modules'] === 'null' || options['css-modules'] === null)
|
46 | return null;
|
47 |
|
48 | return options['css-modules'];
|
49 | }
|