简体   繁体   English

如何在sails.js中使用.less文件?

[英]How use .less files in sails.js?

I'm reading http://sailsjs.org/#!documentation/assets but I don't figure out how use .less files. 我正在阅读http://sailsjs.org/#!documentation/assets但我不知道如何使用.less文件。

I put vairables.less and bootswatch.less both in assets/linker/styles/ 我把资产/链接器/样式/中的vairables.less和bootswatch.less都放了

I expected that grunt would have compiled both files but it didn't, and I got errors in the browser console instead: 我希望grunt会编译这两个文件,但它没有,我在浏览器控制台中遇到错误:

GET http://localhost:5000/linker/styles/bootstrap-responsive.css 404 (Not Found) (index):14
GET http://localhost:5000/linker/styles/bootstrap.css 404 (Not Found) (index):15
GET http://localhost:5000/linker/js/jquery.js 404 (Not Found) (index):29
GET http://localhost:5000/linker/js/socket.io.js 404 (Not Found) (index):30
GET http://localhost:5000/linker/js/sails.io.js 404 (Not Found) (index):31
GET http://localhost:5000/linker/js/app.js 404 (Not Found) (index):32
GET http://localhost:5000/linker/js/bootstrap.js 404 (Not Found) 

If I remove the two .less files it works correctly. 如果我删除两个.less文件它可以正常工作。 What am I missing here? 我在这里错过了什么?

If you are using latest version of Sails.js then put the .less file under assets/styles directory and include it in importer.less file like below: 如果您使用的是最新版本的Sails.js,那么将.less文件放在assets / styles目录下,并将其包含在importer.less文件中,如下所示:

/**
 * importer.less
 *
 * By default, new Sails projects are configured to compile this file
 * from LESS to CSS.  Unlike CSS files, LESS files are not compiled and
 * included automatically unless they are imported below.
 *
 * The LESS files imported below are compiled and included in the order
 * they are listed.  Mixins, variables, etc. should be imported first
 * so that they can be accessed by subsequent LESS stylesheets.
 *
 * (Just like the rest of the asset pipeline bundled in Sails, you can
 * always omit, customize, or replace this behavior with SASS, SCSS,
 * or any other Grunt tasks you like.)
 */



// For example:
//
// @import 'variables/colors.less';
// @import 'mixins/foo.less';
// @import 'mixins/bar.less';
// @import 'mixins/baz.less';
//
// @import 'styleguide.less';
// @import 'pages/login.less';
// @import 'pages/signup.less';
//
// etc.
@import 'custom.less';

I have decided to not use the sails default importer. 我决定不使用sails默认导入器。 Mostly because I find it bad, too much based on configuration over convention. 主要是因为我发现它很糟糕,太多基于配置超过约定。 So I have made my own dynamic assets loader based on convention over configuration. 所以我根据约定优于配置创建了自己的动态资源加载器。

Basically, in mine, there is nothing more to do, the assets will be applied based on the controller, controller action, theme and layout used. 基本上,在我的,没有更多的事情要做,资产将根据控制器,控制器动作,主题和使用的布局来应用。 And it still use LESS. 它仍然使用LESS。

Here is a simple project based on sails 0.10.5 : https://github.com/Vadorequest/sails-dynamic-assets 这是一个基于风帆0.10.5的简单项目: https//github.com/Vadorequest/sails-dynamic-assets

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM