forked from systemjs/plugin-less
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathless.js
38 lines (32 loc) · 1.18 KB
/
less.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var CSSPluginBase = require('css/css-plugin-base.js');
var isWin = typeof process != 'undefined' && process.platform.match(/^win/);
function fromFileURL(url) {
return url.substr(7 + !!isWin).replace(/\//g, isWin ? '\\' : '/');
}
module.exports = new CSSPluginBase(function compile(style, address, opts) {
var loader = this;
// use a file path in Node and a URL in the browser
var filename = this.builder ? fromFileURL(address) : address;
return System['import']('lesscss', module.id)
.then(function(less) {
return less.render(style, {
filename: filename,
rootpath: !loader.builder && filename.replace(/[^/]+$/, ''),
paths: opts.fileAsRoot && [filename.replace(/[^/]+$/, '')],
relativeUrls: opts.relativeUrls || false,
sourceMap: loader.builder && {
sourceMapBasepath: filename.replace(/[^/]+$/, '')
}
});
})
.then(function(output) {
return {
css: output.css + (loader.builder ? '' : ('/*# sourceURL=' + filename + '*/')),
map: output.map,
// style plugins can optionally return a modular module
// source as well as the stylesheet above
moduleSource: null,
moduleFormat: null
};
});
});