正确的Autoprefix插件为我的less中间件节点expressjs

目前我使用较less的中间件( https://www.npmjs.com/package/less-middleware )。 我不满意这个解决scheme,因为less-middlware创build一个编译的css文件。 我想要一个记忆的解决scheme,我可以通过expressjs路由。

此外,我想与一个适当的autoprefix解决scheme,因为有许多很好的CSS技术,我不能使用,因为我需要很多时间来添加供应商的前缀。

  1. 有没有人知道一个更好的解决scheme,即时编译而不输出一个单独的CSS文件。
  2. 这个解决scheme可以提供某种自动修复function吗?
  3. 提供较less的中间件是否提供自动修复function? 我还没有find那个方向。

你应该尝试重新格式化你的问题,因为:

要求我们推荐或查找书籍,工具,软件库,教程或其他非现场资源的问题与Stack Overflow无关,因为它们倾向于吸引自以为是的答案和垃圾邮件。 相反,请描述这个问题,到目前为止已经做了什么来解决这个问题。

我发现根据他们的package.json文件https://github.com/toogle/express-less/blob/master/lib/express-less.js,Express LESS中间件使用最新版本的Node Less。

在他们的代码中调用less.render()在这里: https : //github.com/toogle/express-less/blob/master/lib/express-less.js#L68和更多的信息可以在这里find: http:/ / /lesscss.org/usage/#programmatic-usage

从版本2以来,您可以使用插件。 一个autoprefix插件可在: https : //github.com/less/less-plugin-autoprefix

所以你应该可以使用下面的代码:

 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] })); 

另请参阅: http : //lesscss.org/usage/#plugins-using-a-plugin-in-code

注意我没有testing上面的代码。 我想知道如何设置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] })); 

根据Less Engine的文档,使用插件的方式如下:

less.render(myCSS, { plugins: [myPlugin] })

资料来源: http : //lesscss.org/usage/#plugins-using-a-plugin-in-code

然后根据Less Middleware的文档,将选项添加到render()函数的第二个参数的方法如下:

options.render以最小的默认值或中间件的变化直接传递给less.render

来源: https : //github.com/emberfeather/less.js-middleware#render-options

所以根据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 ] } })); 

这是在NodeAtlas NPM模块中实施和testing的 。