Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 1e38358

Browse files
author
vakrilov
committed
refactor: add check for css-loader
1 parent 3305ee4 commit 1e38358

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

Diff for: apply-css-loader.js

+33-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,43 @@
1+
const cssLoaderWarning = "The apply-css-loader expects the file to be pre-processed by css-loader. It might not work properly. Please check your webpack configuration";
2+
3+
function checkForCssLoader(loaders, loaderIndex) {
4+
if (!loaders) {
5+
return false;
6+
}
7+
8+
for (var i = loaderIndex + 1; i < loaders.length; i++) {
9+
const loader = loaders[i];
10+
if (loader.path && loader.path.indexOf("css-loader") > 0) {
11+
return true;
12+
}
13+
}
14+
15+
return false;
16+
}
17+
118
module.exports = function (content, map) {
219
if (this.request.match(/\/app\.(css|scss|less|sass)$/)) {
320
return content;
421
}
22+
23+
// Emit a warning if the file was not processed by the css-loader.
24+
if (!checkForCssLoader(this.loaders, this.loaderIndex)) {
25+
this.emitWarning(new Error(cssLoaderWarning));
26+
}
27+
528
content += `
629
const application = require("tns-core-modules/application");
730
require("tns-core-modules/ui/styling/style-scope");
831
9-
exports.forEach(cssExport => {
10-
if (cssExport.length > 1 && cssExport[1]) {
11-
// applying the second item of the export as it contains the css contents
12-
application.addCss(cssExport[1]);
13-
}
14-
});
15-
`;
32+
if (typeof exports.forEach === "function") {
33+
exports.forEach(cssExport => {
34+
if (cssExport.length > 1 && cssExport[1]) {
35+
// applying the second item of the export as it contains the css contents
36+
application.addCss(cssExport[1]);
37+
}
38+
});
39+
}
40+
`;
1641

1742
this.callback(null, content, map);
18-
}
43+
}

0 commit comments

Comments
 (0)