This repository was archived by the owner on Oct 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathless.js
More file actions
52 lines (44 loc) · 1.78 KB
/
less.js
File metadata and controls
52 lines (44 loc) · 1.78 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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) {
var outputSourceMap = !!loader.builder;
var sourceMapBasepath = filename.replace(/[^/]+$/, '');
// NB: sourceMap must be imported in a script tag before this module is imported
// download here: https://github.com/mozilla/source-map/tree/master/dist
// see https://github.com/less/less.js/issues/1541 for details
if (!this.builder && loader.inlineCssSourceMaps && (typeof sourceMap !== 'undefined')) {
outputSourceMap = true;
less.environment.getSourceMapGenerator = function() {
return sourceMap.SourceMapGenerator;
};
sourceMapBasepath = new URL(filename).pathname;
}
return less.render(style, {
filename: filename,
rootpath: !loader.builder && filename.replace(/[^/]+$/, ''),
paths: opts.fileAsRoot && [filename.replace(/[^/]+$/, '')],
relativeUrls: opts.relativeUrls || false,
sourceMap: outputSourceMap && {
sourceMapBasepath: sourceMapBasepath
}
});
})
.then(function(output) {
return {
css: output.css + (output.map ? '' : ('/*# sourceURL=' + filename + '*/')),
map: output.map,
// style plugins can optionally return a modular module
// source as well as the stylesheet above
moduleSource: null,
moduleFormat: null
};
});
});