如何在 `express-js` 中使用 `less` 来缩小 CSS?
app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] }));
这是我的 app.js 中启用 less
的行。如何将 { compress: true }
参数传递给它?
app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] }));
That's the line in my app.js that enables less
. How can I pass the { compress: true }
parameter to it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我也遇到了这个问题,并认为与其他人分享这可能很有用:
有关 minify-process 的更多信息和设置可以在 少中间件 README.md
I also had this problem and thought this can be useful to share with others:
More information and settings about the minify-process can be found in the Less-Middleware README.md
使用 less4clients 和压缩选项我弃用并删除了 less4clients 包使用 less css 渲染中间件扩展了express.js 服务器,以动态渲染更少的文件到 css(并将结果缓存在内存中),以支持我的一个名为 DocPad 可让您使用任何所需的预处理器。
截至撰写本文时,它还没有像 less4clients 这样易于使用的快速中间件,但是这样的东西很快就会出现在路线图上。相反,您可以独立使用它或通过其 API 使用它。
事后看来,我应该保留 less4clients 可用,并且只是在自述文件中指出 DocPad 是一种新的做事方式,但我从未意识到 less4clients 实际上被任何人使用,因为 DocPad 已经获得了如此多的关注。
use less4clients with the compress optionI deprecated and removed the less4clients package which extends a express.js server with a less css rendering middleware to render less files to css on the fly (and cache the results in memory) in favor of a newer project of mine called DocPad that lets you use any pre-processor you want.
As of this time of writing, it does not have an easy to use express middleware like less4clients, however such a thing is on the roadmap soon. Instead you can use it standalone or via its API.
In hindsight I should have kept less4clients available and just stated in it's readme that DocPad is the new way of doing things, but I never realised less4clients was actually being used by anyone as DocPad has already gained so much attention.
遗憾的是,您不能使用 connect 的编译器来做到这一点。 connect.compiler(即express.compiler)仅允许您设置要使用的编译器,但不允许设置各个编译器的任何选项。如果您想设置 less.js 的压缩标志,您将需要创建自己的使用 less.js 模块的中间件。
Sadly, you can't and use connect's compiler to do it. The connect.compiler, which is what express.compiler is, only allows you to set which compilers to use, but not any options for the individual compilers. If you want to set less.js's compress flag you will need to create you're own middleware that user the less.js module.