2

我正在迁移到 systemjs,主要是因为它支持模块,这使得迁移到 ES6 更简单。

systemjs CSS 插件允许像这样优雅的导入:

System.import('bootstrap/css/bootstrap.css!');

但这是异步加载的,因此加载需要在服务器生成页面的其余部分之前加载的 CSS 是不切实际的。所以我必须恢复到繁琐的包 URL。(当版本发生变化时会中断——而且似乎通常很hacky——因为JSPM应该管理这些细节?)

<link rel="stylesheet" href="/res/packages/github/twbs/bootstrap@3.3.5/css/bootstrap.css">

有最佳实践吗?其实systemjs的实际使用有什么有用的例子吗?

4

1 回答 1

2

您可以隐藏正文,创建一个加载资产的 javascript 模块并在资产加载后显示正文:

资产.js

import 'bootstrap/css/bootstrap.css!';

然后在您的index.html文件中:

System.import('assets.js').then(function(){
   //Now your styles are loaded. You may fade in/display your content.
   document.querySelector('body').style.display = 'block';
}); //Add the JS extension according to your SystemJS configuration
于 2015-09-09T13:31:33.330 回答