mirror of
https://github.com/less/less.js.git
synced 2026-01-22 05:37:56 -05:00
Allow adding plugins via @import (plugin)
This commit is contained in:
@@ -64,7 +64,7 @@ module.exports = function(environment) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tryAppendLessExtension) {
|
||||
if (tryAppendLessExtension && !importOptions.plugin) {
|
||||
path = fileManager.tryAppendLessExtension(path);
|
||||
}
|
||||
|
||||
@@ -101,7 +101,19 @@ module.exports = function(environment) {
|
||||
newFileInfo.reference = true;
|
||||
}
|
||||
|
||||
if (importOptions.inline) {
|
||||
if (importOptions.plugin) {
|
||||
try {
|
||||
var plugin = require(resolvedFilename);
|
||||
|
||||
if ( -1 === newEnv.pluginManager.installedPlugins.indexOf( plugin )) {
|
||||
newEnv.pluginManager.addPlugin(plugin);
|
||||
}
|
||||
fileParsedFunc(null, "", resolvedFilename);
|
||||
} catch(e) {
|
||||
fileParsedFunc(e, "", resolvedFilename);
|
||||
}
|
||||
|
||||
} else if (importOptions.inline) {
|
||||
fileParsedFunc(null, contents, resolvedFilename);
|
||||
} else {
|
||||
new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {
|
||||
|
||||
@@ -1212,7 +1212,7 @@ var Parser = function Parser(context, imports, fileInfo) {
|
||||
},
|
||||
|
||||
importOption: function() {
|
||||
var opt = parserInput.$re(/^(less|css|multiple|once|inline|reference|optional)/);
|
||||
var opt = parserInput.$re(/^(less|css|multiple|once|inline|reference|optional|plugin)/);
|
||||
if (opt) {
|
||||
return opt[1];
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ Import.prototype.accept = function (visitor) {
|
||||
this.features = visitor.visit(this.features);
|
||||
}
|
||||
this.path = visitor.visit(this.path);
|
||||
if (!this.options.inline && this.root) {
|
||||
if (!this.options.plugin && !this.options.inline && this.root) {
|
||||
this.root = visitor.visit(this.root);
|
||||
}
|
||||
};
|
||||
@@ -120,7 +120,9 @@ Import.prototype.eval = function (context) {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.options.inline) {
|
||||
if (this.options.plugin) {
|
||||
return [];
|
||||
} else if (this.options.inline) {
|
||||
var contents = new Anonymous(this.root, 0, {filename: this.importedFilename}, true, true);
|
||||
return this.features ? new Media([contents], this.features.value) : [contents];
|
||||
} else if (this.css) {
|
||||
|
||||
Reference in New Issue
Block a user