如何在 `express-js` 中使用 `less` 来缩小 CSS?

发布于 2024-12-03 16:21:24 字数 192 浏览 1 评论 0原文

  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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

聊慰 2024-12-10 16:21:24

我也遇到了这个问题,并认为与其他人分享这可能很有用:

var lessMiddleware = require('less-middleware');
app.use(lessMiddleware({ src: __dirname + '/public', compress: true, optimization: 2 }));

有关 minify-process 的更多信息和设置可以在 少中间件 README.md

I also had this problem and thought this can be useful to share with others:

var lessMiddleware = require('less-middleware');
app.use(lessMiddleware({ src: __dirname + '/public', compress: true, optimization: 2 }));

More information and settings about the minify-process can be found in the Less-Middleware README.md

欢烬 2024-12-10 16:21:24

使用 less4clients 和压缩选项

我弃用并删除了 less4clients 包使用 less css 渲染中间件扩展了express.js 服务器,以动态渲染更少的文件到 css(并将结果缓存在内存中),以支持我的一个名为 DocPad 可让您使用任何所需的预处理器。

截至撰写本文时,它还没有像 less4clients 这样易于使用的快速中间件,但是这样的东西很快就会出现在路线图上。相反,您可以独立使用它或通过其 API 使用它。

事后看来,我应该保留 less4clients 可用,并且只是在自述文件中指出 DocPad 是一种新的做事方式,但我从未意识到 less4clients 实际上被任何人使用,因为 DocPad 已经获得了如此多的关注。

use less4clients with the compress option

I 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.

_失温 2024-12-10 16:21:24

遗憾的是,您不能使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文