ngx-unused-css
Version:
Detect unused CSS in angular components
36 lines • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var fs_1 = (0, tslib_1.__importDefault)(require("fs"));
var findUnusedCss_1 = (0, tslib_1.__importDefault)(require("../main/findUnusedCss"));
/**
* Returns array of classes/attributes not used in html
*
* @param cssPath - styling file path
* @param htmlContent - html content to analyse
* @param htmlPath - html file path
* @returns Promise<([string[], string])>
*/
function unusedClassMapper(cssPath, htmlContent, htmlPath, config) {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var classes;
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0:
try {
// Try to read styling file path in order to determine if file exist
fs_1.default.readFileSync(cssPath);
}
catch (error) {
throw new Error('Styling file for component ' + htmlPath + ' not found, skipping...');
}
return [4 /*yield*/, (0, findUnusedCss_1.default)(htmlContent, cssPath, config)];
case 1:
classes = _a.sent();
return [2 /*return*/, [classes, htmlPath]];
}
});
});
}
exports.default = unusedClassMapper;
//# sourceMappingURL=unusedClassMapper.js.map