Skip to content

Commit 32eefd9

Browse files
author
Andrew Levine
committed
Add option to warn at runtime when non-existent properties are accessed on css module
1 parent 199897f commit 32eefd9

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/loader.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,16 @@ module.exports = function(content, map) {
8888

8989
var exportJs = compileExports(result, importItemMatcher.bind(this), camelCaseKeys);
9090
if (exportJs) {
91-
exportJs = "exports.locals = " + exportJs + ";";
91+
if (query.cssModuleDevWarnings) {
92+
exportJs = "exports.locals = new Proxy(" + exportJs + "," +
93+
"{ get(target, property) { " +
94+
"if (typeof target[property] !== 'string' && property !== '__esModule') {" +
95+
"console.warn(`Attempted to access non-existent className '${property} on CSS module'`)" +
96+
"} else { return target[property] }" +
97+
"}})";
98+
} else {
99+
exportJs = "exports.locals = " + exportJs + ";"
100+
}
92101
}
93102

94103
var moduleJs;

0 commit comments

Comments
 (0)