Skip to content
This repository was archived by the owner on Oct 30, 2020. It is now read-only.

Commit 15fe6c7

Browse files
authored
Merge pull request #3 from Jimdo/warn-if-modules-option-not-set
early return and warn if modules option not set
2 parents 66cba08 + c5e39a2 commit 15fe6c7

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"css modules webpack typings"
2626
],
2727
"dependencies": {
28-
"graceful-fs": "4.1.4"
28+
"graceful-fs": "4.1.4",
29+
"loader-utils": "0.2.16"
2930
},
3031
"devDependencies": {
3132
"babel-cli": "6.10.1",

src/index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
import cssLoader from 'css-loader';
22
import cssLocalsLoader from 'css-loader/locals';
3+
import loaderUtils from 'loader-utils';
34
import {
45
generateInterface,
56
filenameToTypingsFilename,
67
} from './cssModuleToInterface';
78
import * as persist from './persist';
89

10+
function delegateToCssLoader(ctx, input, callback) {
11+
ctx.async = () => callback;
12+
cssLoader.call(ctx, input);
13+
}
14+
915
module.exports = function(input) {
1016
if(this.cacheable) this.cacheable();
1117

1218
// mock async step 1 - css loader is async, we need to intercept this so we get async ourselves
1319
const callback = this.async();
20+
21+
const query = loaderUtils.parseQuery(this.query);
22+
const moduleMode = query.modules || query.module;
23+
if (!moduleMode) {
24+
console.warn('Typings for CSS-Modules: option `modules` is not active - skipping extraction work...');
25+
return delegateToCssLoader(ctx, input, callback);
26+
}
27+
1428
// mock async step 2 - offer css loader a "fake" callback
1529
this.async = () => (err, content) => {
1630
const cssmodules = this.exec(content, this.resource);
@@ -20,8 +34,7 @@ module.exports = function(input) {
2034
const cssModuleInterface = generateInterface(cssmodules, requestedResource);
2135
persist.writeToFileIfChanged(cssModuleInterfaceFilename, cssModuleInterface);
2236
// mock async step 3 - make `async` return the actual callback again before calling the 'real' css-loader
23-
this.async = () => callback;
24-
cssLoader.call(this, input);
37+
delegateToCssLoader(this, input, callback);
2538
};
2639
cssLocalsLoader.call(this, input);
2740
}

0 commit comments

Comments
 (0)