从Less版本2开始,您可以使用插件.您还可以使用这些插件向Less添加自定义功能,例如:https: //github.com/less/less-plugin-advanced-color-functions/和https://github.com/bassjobsen/less-plugin- cubehelix
灵感来自https://github.com/less/less.js/issues/2341我希望将自定义功能添加twotimesandten到更少,以便:
@start: 10;
.test {
result: twotimesandten(@start);
}
Run Code Online (Sandbox Code Playgroud)
编译成:
.test {
result: 30;
}
Run Code Online (Sandbox Code Playgroud)
在阅读http://lesscss.org/usage/#plugins-for-plugin-authors后,我想知道该怎么做?
我正在尝试使用less-plugin-clean-css和grunt-contrib-less,但我无法让它运行.似乎grunt配置无法找到或安装插件.这是我维护的一个bootstrap的分支.
我用以下内容更新了Gruntfile.js:
grunt.initConfig({
...
less: {
compileCore: {
options: {
strictMath: true,
sourceMap: true,
outputSourceFiles: true,
+ plugins: [
+ (new require('less-plugin-clean-css')({
+ "advanced": true,
+ "compatibility": "ie8"
+ }))
+ ],
sourceMapURL: '<%= pkg.name %>.css.map',
sourceMapFilename: 'dist/css/<%= pkg.name %>.css.map'
},
src: 'less/bootstrap.less',
dest: 'dist/css/<%= pkg.name %>.css'
...
}
},
Run Code Online (Sandbox Code Playgroud)
安装插件:
npm install less-plugin-clean-css --save-dev
Run Code Online (Sandbox Code Playgroud)
运行grunt并获取此错误:
Running "less:compileCore" (less) task
>> TypeError: Cannot read property 'install' of undefined
Run Code Online (Sandbox Code Playgroud)
我错过了什么?