fuse-box
Version:
Fuse-Box a bundler that does it right
42 lines (40 loc) • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
let less;
class LESSPluginClass {
constructor(options = {}) {
this.test = /\.less$/;
this.options = options;
}
init(context) {
context.allowExtension(".less");
}
transform(file) {
file.addStringDependency("fuse-box-css");
const context = file.context;
const options = Object.assign({}, this.options);
file.loadContents();
const sourceMapDef = {
sourceMapBasepath: ".",
sourceMapRootpath: file.info.absDir,
};
if (!less) {
less = require("less");
}
options.filename = file.context.homeDir + (options.filename || file.info.fuseBoxPath);
if ("sourceMapConfig" in context) {
options.sourceMap = Object.assign({}, sourceMapDef, options.sourceMap || {});
}
return less.render(file.contents, options).then(output => {
if (output.map) {
file.sourceMap = output.map;
}
file.contents = output.css;
});
}
}
exports.LESSPluginClass = LESSPluginClass;
exports.LESSPlugin = (opts) => {
return new LESSPluginClass(opts);
};
//# sourceMappingURL=LESSPlugin.js.map