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

查看:14
本文介绍了如何在 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天全站免登陆