如何在Meteor.js中仅显式加载特定的(不是全部)css文件 [英] How to expicitly load only specific (not all) css files in Meteor.js

查看:98
本文介绍了如何在Meteor.js中仅显式加载特定的(不是全部)css文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Meteor.js开发一个普通的网站(而不是一页Web应用程序),并且我只希望为每个页面加载特定的CSS文件.因此,并非所有页面都共享相同的CSS代码. 有可能吗?

解决方案

首先,如果您使用的是Meteor,则不是在构建常规"站点,而是在构建功能非常强大的SPA(单页应用程序).您可以通过引入路由来模仿常规"网站,请尝试 IronRouter .

现在确定有关CSS的信息.部署Meteor后,所有CSS和JS都将合并并缩小.因此,如果您想实现自己的要求,则需要添加一个像这样的程序包.

https://atmospherejs.com/mrt/external-file-loader

> https://github.com/davidd8/meteor-external-file-loader

然后将其附加以在创建模板后触发:

Template.myCustomTemplate.created = function() {
  Meteor.Loader.loadCss("//example.com/myCSS/style.css");
};

我相信您也可以通过Meteor的Asset API从Meteor服务器加载CSS.在此处阅读更多信息: https://docs.meteor.com/#/full/assets

I want to develop a usual website with Meteor.js (not one-page web app) and I want to load only specific css files for every page. So not all pages share the same css code. Is it possible?

解决方案

First off if you are using Meteor you are not building a "usual" site, you are building a very powerful SPA (single page application). You can imitate a "usual" website with introducing routing, try IronRouter.

OK now about CSS. Once you deploy Meteor all your CSS and JS are merged and minified. So if you want to achieve what you are asking you will need to add a package like this one.

https://atmospherejs.com/mrt/external-file-loader

https://github.com/davidd8/meteor-external-file-loader

Then attach it to trigger once a template is created:

Template.myCustomTemplate.created = function() {
  Meteor.Loader.loadCss("//example.com/myCSS/style.css");
};

I believe you could also load the CSS from the Meteor server through Meteor's Asset API. Read more here: https://docs.meteor.com/#/full/assets

这篇关于如何在Meteor.js中仅显式加载特定的(不是全部)css文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆