Sails不会在资产文件夹内注入文件 [英] Sails is not injecting the files within the assets folder
问题描述
我刚刚在我的服务器上安装了全新的sails(v0.11.0),在检查完这些并在控制器上工作之后,我发现包含在assets文件夹中的css,js和templates文件没有被注入到布局中,如果有任何理由发生这种情况?我的意思是,这是一个干净的新鲜帆安装....
在我的追求让SailsJS自动注入样式表在我的案例中,在views / layouts / layout.handlebars下的布局文件中,我发现了一些东西......
当你第一次创建你的sails应用程序:
$ b
sails新APPNAME --template = handlebars --verbose
注意:以下链接解释了上述语法...
-
转到config> views.js
它会说:
layout:'layouts / layout.handlebars'$ c $
改为:
layout:'layouts / layout',
-
转至任务> config> sails-linker.js
因为我现在处于开发模式, Ctrl + f搜索:
devStylesdevStyles:{
options:{
startTag:'<! - -STYLES - >',
endTag:'<! - STYLES END - >',
fileTmpl:'< link rel =stylesheethref =%s> ;',
appRoot:'.tmp / public'
},
文件:{
'.tmp / public / ** / *。html': require('../ pipeline')。cssFilesToInject,
'views / ** / *。html':require('../ pipeline')。cssFilesToInject,
'views / ** / * .ejs':require('../ pipeline')。cssFilesToInject
//添加句柄注入
}
},
注意它有.html,& .ejs类型被注入,但不是.handlebars
添加以下行:
' / ** / *。handlebars':require('../ pipeline')。cssFilesToInject
其中我评论道:
//在这里添加把手注射
应该能够将一个.css文件放入assets> styles并自动复制到.tmp / public / styles中。
运行:
sails lift
在命令提示符下输入约20秒钟让样式表在您的routes.js中的任何页面上显示其样式
'/':{
view:'index'
}
正如你所看到的,我做了一个新的.handlebars文件index.handlebars并将其设置为我的根级页面。您可能需要刷新页面一两次以获取新自动注入的CSS。
在首次创建SailsJS项目时,似乎不再需要追加 - linker
。还有fyi,我使用的是sails版本0.11.0
另外如果你运行 sails lift --verbose
下面的行是你如何知道.handlebars注入正在工作
verbose:Grunt :: Fileviews / layouts / layout.handlebars已更新。
希望这有助于您!
此外,添加Handlebars Helpers时,在文件 helper.js
中,它应该位于config> helper.js中
在 helper.js
file我发现我必须要求如下的句柄
handlebars = require 'sails / node_modules / express-handlebars / node_modules / handlebars');
I just did a fresh installation of sails (v0.11.0) in my server and after checking this up and working on controllers I found that css, js and templates files included into the assets folders are not being injected to the layout, if there any reason for this to happen? I mean, it is a clean fresh sails installation....
In my quest to get SailsJS to auto-inject stylesheets into the layout file under views/layouts/layout.handlebars in my case, I've found out a couple things...
When you first create your sails app using:
sails new APPNAME --template=handlebars --verbose
note: link below explains above syntax...
Using handlebars templates in Sails.js
Go to config > views.js It will say:
layout: 'layouts/layout.handlebars'
change to:
layout: 'layouts/layout',
Go to tasks > config > sails-linker.js Because I'm in development mode right now I will Ctrl + f searching for: "devStyles"
devStyles: { options: { startTag: '<!--STYLES-->', endTag: '<!--STYLES END-->', fileTmpl: '<link rel="stylesheet" href="%s">', appRoot: '.tmp/public' }, files: { '.tmp/public/**/*.html': require('../pipeline').cssFilesToInject, 'views/**/*.html': require('../pipeline').cssFilesToInject, 'views/**/*.ejs': require('../pipeline').cssFilesToInject //ADD HANDLEBARS INJECTION HERE } },
Notice it has .html, & .ejs types being injected but not .handlebars
add this line:
'views/**/*.handlebars': require('../pipeline').cssFilesToInject
where I commented:
//ADD HANDLEBARS INJECTION HERE
At this point you should be able to drop a .css file into assets > styles and have it auto-copied to .tmp/public/styles
run:
sails lift
in your command prompt and give it about 20 seconds or so to have the stylesheet manifest its style on whatever page you have in your routes.js
'/': {
view: 'index'
}
As you can see, I made a new .handlebars file index.handlebars and set it as my root level page. You may have to refresh the page a time or two to get the newly auto-injected CSS to show.
P.S. It appears there is no more need to append --linker
when first creating a SailsJS project. Also fyi, I'm using sails version 0.11.0
Also if you run sails lift --verbose
the line below is how you know the .handlebars injection is working
verbose: Grunt :: File "views/layouts/layout.handlebars" updated.
Hope this helps!
Also, when adding Handlebars Helpers they should go in a file helper.js
which should be located in config > helper.js
At the top of the helper.js
file I found I had to require handlebars as follows
handlebars = require('sails/node_modules/express-handlebars/node_modules/handlebars');
这篇关于Sails不会在资产文件夹内注入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!