【问题标题】:Issue using Flask-Assets to compile less files使用 Flask-Assets 编译较少文件的问题
【发布时间】:2014-02-02 06:32:41
【问题描述】:

我目前正在尝试设置一个 Flask 网络应用程序,并尝试使用 Flask-Assets 将我的 less 文件编译成缩小的 css。

这是创建捆绑包的 assets.py 文件。

from flask_assets import Bundle

common_css = Bundle(
    'vendor/less/theme.less',
    filters='less',
    output='static/css/common.css',
    )

我得到的错误是:

OSError: [Errno 2] No such file or directory

less filterwebassets 文档中,它说:

This depends on the NodeJS implementation of less, installable via npm. To use the old Ruby-based version (implemented in the 1.x Ruby gem), see Less.

...

LESS_BIN (binary)
    Path to the less executable used to compile source files. By default, the filter will attempt to run lessc via the system path.

我使用$ npm install less 安装了less,但由于某种原因,webassets 似乎无法使用它。

当我尝试使用不同的过滤器时,webassets 可以成功创建捆绑包。

谢谢!

【问题讨论】:

    标签: python flask less webassets flask-assets


    【解决方案1】:

    npm install 默认在当前目录下安装包(你应该可以在那里找到node_modules 目录)。你有两个选择:

    1. 全局安装lessc

      $ npm install -g less
      

      这样网络资产将能够自己找到它。

    2. 提供lessc 可执行文件的完整路径:

      assets = Environment(app)
      assets.config['less_bin'] = '/path/to/lessc'
      

      路径应该是<some_directory>/node_modules/.bin/lessc

    【讨论】:

    • 请注意,这仅适用于我使用完整路径来 lessc 而不是相对于我的项目的路径。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-09
    • 1970-01-01
    相关资源
    最近更新 更多