Pau*_*eri 6 python less flask webassets flask-assets
我目前正在尝试设置Flask Web应用程序,并尝试使用Flask-Assets将较少的文件编译为缩小的CSS.
这是我创建捆绑包的assets.py文件.
from flask_assets import Bundle
common_css = Bundle(
'vendor/less/theme.less',
filters='less',
output='static/css/common.css',
)
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
OSError: [Errno 2] No such file or directory
Run Code Online (Sandbox Code Playgroud)
在较少过滤器的webassets文档中,它说:
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.
Run Code Online (Sandbox Code Playgroud)
我安装less使用$ npm install less,但由于某种原因它看起来webassets不能使用它.
当我尝试使用不同的过滤器时,webassets可以成功创建捆绑包.
谢谢!
npm install默认情况下在当前目录中安装软件包(您应该能够在node_modules那里找到目录).你有两个选择:
lessc全球安装:
$ npm install -g less
Run Code Online (Sandbox Code Playgroud)
这样webassets就能够自己找到它.
提供lessc可执行文件的完整路径:
assets = Environment(app)
assets.config['less_bin'] = '/path/to/lessc'
Run Code Online (Sandbox Code Playgroud)
路径应该是<some_directory>/node_modules/.bin/lessc.