Currently I use less-middleware (https://www.npmjs.com/package/less-middleware). I am not satisfied with this solution, because less-middlware create a compiled css file. I want a memorized solution I can route via expressjs.
目前我使用较少的中间件(https://www.npmjs.com/package/less-middleware)。我对这个解决方案不满意,因为less-middlware会创建一个已编译的css文件。我想要一个记忆的解决方案,我可以通过expressjs路由。
Besides, I want to work with a proper autoprefix solution, because there are many nice css technologies I cant use because I would need to much time to add the vendor prefixes.
此外,我想使用适当的autoprefix解决方案,因为有许多不好的css技术我无法使用,因为我需要很多时间来添加供应商前缀。
如果没有输出单独的css文件,任何人都可以知道一个更好的解决方案,即可减少即时编译。
这个解决方案能提供某种自动修复功能吗?
提供较少中间件提供自动修复功能。我没有找到那个方向的东西。
1
You should try to reformat your question, because of:
您应该尝试重新格式化您的问题,因为:
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
要求我们推荐或找到书籍,工具,软件库,教程或其他场外资源的问题都是Stack Overflow的主题,因为它们往往会吸引固执己见的答案和垃圾邮件。相反,描述问题以及到目前为止已经做了什么来解决它。
I found https://github.com/toogle/express-less/blob/master/lib/express-less.js according their package.json file, Express LESS middleware uses the latest version of Node Less.
我根据他们的package.json文件找到了https://github.com/toogle/express-less/blob/master/lib/express-less.js,Express LESS中间件使用最新版本的Node Less。
In their code the call less.render()
here: https://github.com/toogle/express-less/blob/master/lib/express-less.js#L68 and more information can be found here: http://lesscss.org/usage/#programmatic-usage
在他们的代码中调用less.render()在这里:https://github.com/toogle/express-less/blob/master/lib/express-less.js#L68和更多信息可以在这里找到:http:/ /lesscss.org/usage/#programmatic-usage
Since version 2 of Less you can use plugins. An autoprefix plugin is available at: https://github.com/less/less-plugin-autoprefix
从Less版本2开始,您可以使用插件。 autoprefix插件可从以下网址获得:https://github.com/less/less-plugin-autoprefix
So you should be able to use the follow code:
所以你应该能够使用以下代码:
var express = require('express'),
expressLess = require('express-less'),
autoprefixer = require('less-plugin-autoprefix');
var app = express();
app.use('/less-css', expressLess(__dirname + '/less', { plugins: [autoprefixer] }));
Also see: http://lesscss.org/usage/#plugins-using-a-plugin-in-code
另见:http://lesscss.org/usage/#plugins-using-a-plugin-in-code
Notice i did not test the above code. I wondered how to set the autoprefixer option. According to https://github.com/plus3network/gulp-less#using-plugins you should use:
注意我没有测试上面的代码。我想知道如何设置autoprefixer选项。根据https://github.com/plus3network/gulp-less#using-plugins你应该使用:
var autoprefixerPlugin = require('less-plugin-autoprefix'),
autoprefixer = new autoprefixerPlugin({options});
var app = express();
app.use('/less-css', expressLess(__dirname + '/less', { plugins: [autoprefixer] }));
1
According to the documentation of Less Engine, the way to use a plugin is the following:
根据Less Engine的文档,使用插件的方法如下:
less.render(myCSS, { plugins: [myPlugin] })
less.render(myCSS,{plugins:[myPlugin]})
Source: http://lesscss.org/usage/#plugins-using-a-plugin-in-code
Then according to the documentation of Less Middleware, the way to add options into second parameter of render()
function is the following:
然后根据Less Middleware的文档,将选项添加到render()函数的第二个参数中的方法如下:
The
options.render
is passed directly into theless.render
with minimal defaults or changes by the middleware.options.render直接传递给less.render,具有最小的默认值或中间件的更改。
Source: https://github.com/emberfeather/less.js-middleware#render-options
So according to the documentation of Less Autoprefixer ande the documentation of Express Engine, the definitive and true way to use it is using this code:
因此,根据Less Autoprefixer的文档和Express Engine的文档,使用它的确切和真实的方法是使用以下代码:
var express = require('express'),
lessMiddleware = require('less-middleware'),
lessPluginAutoprefix = require('less-plugin-autoprefix'),
app = express(),
autoprefixPlugin = new lessPluginAutoprefix({
browsers: ["last 2 versions"]
});
app.use(lessMiddleware(path.join(__dirname, 'public'), {
render: {
plugins: [
autoprefixPlugin
]
}
}));
This was implemented and tested in the NodeAtlas NPM module.
这是在NodeAtlas NPM模块中实现和测试的。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2015/05/20/3a6b846d22edc0502c993b536079617b.html。