require-css
===========
RequireJS CSS requiring and optimization, with almond support.
Useful for writing modular CSS dependencies alongside scripts. For an example of widget rendering see [ZestJS](http://zestjs.org).
For LESS inclusion, use [require-less](https://github.com/guybedford/require-less), which behaves and builds the css exactly like this module apart from the preprocessing step.
<a href="https://www.gittip.com/guybedford/"><img src="http://img.shields.io/gittip/guybedford.svg" /></a>
Overview
--------
Allows the construction of scripts that can require CSS, using the simple RequireJS syntax:
```javascript
define(['css!styles/main'], function() {
//code that requires the stylesheet: styles/main.css
});
```
Fully compatible in IE 6+, Chrome 3+, Firefox 3.5+, Opera 10+, iOS.
* **CSS builds** When run as part of a build with the RequireJS optimizer, `css!` dependencies are automatically inlined into the built layer within the JavaScript, fully compatible with layering. CSS injection is performed as soon as the layer is loaded.
* **Option to build separate layer CSS files** A `separateCSS` build parameter allows for built layers to output their css files separately, instead of inline with the JavaScript, for manual inclusion.
* **CSS compression** CSS redundancy compression is supported through the external library, [csso](https://github.com/css/csso).
Installation and Setup
----------------------
Download the require-css folder manually or use Bower:
```bash
bower install require-css
```
To allow the direct `css!` usage, add the following [map configuration](http://requirejs.org/docs/api.html#config-map) in RequireJS:
```javascript
map: {
'*': {
'css': 'require-css/css' // or whatever the path to require-css is
}
}
```
Use Cases and Benefits
----------------------
### Motivation
The use case for RequireCSS came out of a need to manage templates and their CSS together.
The idea being that a CSS require can be a dependency of the code that dynamically renders a template.
When writing a large dynamic application, with templates being rendered on the client-side, it can be beneficial to inject the CSS as templates are required instead
of dumping all the CSS together separately. The added benefit of this is then being able to build the CSS naturally with the RequireJS optimizer,
which also supports [separate build layers](http://requirejs.org/docs/1.0/docs/faq-optimization.html#priority) as needed.
### Script-inlined CSS Benefits
By default, during the build CSS is compressed and inlined as a string within the layer that injects the CSS when run.
If the layer is included as a `<script>` tag, only one browser request is needed instead of many separate CSS requests with `<link>` tags.
Even better than including a layer as a `<script>` tag is to include the layer dynamically with a non-blocking require.
Then the page can be displayed while the layer is still loading asynchronously in the background.
In this case, the CSS that goes with a template being dynamically rendered is loaded with that same script asynchronously.
No longer does it need to sit in a `<link>` tag that blocks the page display unnecessarily.
Modular CSS
-----------
RequireCSS implies a CSS modularisation where styles can be scoped directly to the render code that they are bundled with.
Just like JS requires, the order of CSS injection can't be guaranteed. The idea here is that whenever there are style overrides, they should
be based on using a more specific selector with an extra id or class at the base, and not assuming a CSS load order. Reset and global styles are a repeated dependency of all
modular styles that build on top of them.
Optimizer Configuration
-----------------------
### Basic Usage
Optimizer configuration:
```javascript
{
modules: [
{
name: 'mymodule',
exclude: ['css/normalize']
}
]
}
```
If the contents of 'mymodule' are:
```javascript
define(['css!style', 'css!page'], function(css) {
//...
});
```
Then the optimizer output would be:
-mymodule.js containing:
style.css and page.css which will be dynamically injected
The `css/normalize` exclude is needed due to [r.js issue #289](https://github.com/jrburke/r.js/issues/289)
### Separate File Output
To output the CSS to a separate file, use the configuration:
```javascript
{
separateCSS: true,
modules: [
{
name: 'mymodule'
}
]
}
```
This will then output all the css to the file `mymodule.css`. This configuration can also be placed on the module object itself for layer-specific settings.
Optimization is fully compatible with exclude and include.
### IE8 and 9 Selector Limit
In IE9 and below, there is a maximum limit of 4095 selectors per stylesheet.
In order to avoid this limit, CSS concatenation can be disabled entirely with the `IESelectorLimit` option.
```javascript
{
IESelectorLimit: true,
modules: [
{
name: 'mymodule'
}
]
}
```
Ideally build layers would avoid this limit entirely by naturally being designed to not reach it. This option is really only as a fix when nothing else
is possible as it will degrade injection performance.
This option is also not compatible with the `separateCSS` option.
### Excluding the CSS Module in Production
When dynamic CSS requires are not going to be made in production, a minimal version of RequireCSS can be written by setting a pragma for the build:
```javascript
{
pragmasOnSave: {
excludeRequireCss: true
}
}
```
### siteRoot Configuration
When building the CSS, all URIs are renormalized relative to the site root.
It assumed that the siteRoot matches the build directory in this case.
If this is different, then specify the server path of the siteRoot relative to the baseURL in the configuration.
For example, if the site root is `www` and we are building the directory `www/lib`, we would use the configuration:
```javascript
{
appDir: 'lib',
dir: 'lib-built',
siteRoot: '../',
modules: [
{
name: 'mymodule'
}
]
}
```
### Almond Configuration
Almond doesn't support the `packages` configuration option. When using Almond, rather configuration RequireCSS with map configuration instead, by including the following configuration in the production app:
```javascript
requirejs.config({
map: {
'*': {
css: 'require-css/css'
}
}
});
```
### Disabling the Build
To disable any CSS build entirely, use the configuration option `buildCSS`:
```javascript
{
buildCSS: false,
modules: [
{
name: 'mymodule'
}
]
}
```
CSS requires will then be left in the source "as is". This shouldn't be used with `stubModules`.
CSS Compression
---------------
CSS compression is supported with [csso](https://github.com/css/csso).
To enable the CSS compression, install csso with npm:
```
npm install csso -g
```
The build log will display the compression results.
When running the r.js optimizer through NodeJS, sometimes the global module isn't found. In this case install csso as a local node module so it can be found.
Injection methods
-----------------
When loading a CSS file or external CSS file, a `<link>` tag is used. Cross-browser support comes through a number of careful browser conditions for this.
If CSS resources such as images are important to be loaded first, these can be added to the require through a loader plugin that can act as a preloader such as [image](https://github.com/millermedeiros/requirejs-plugins) or [font](https://github.com/millermedeiros/requirejs-plugins). Then a require can be written of the form:
```javascript
require(['css!my-css', 'image!preload-background-image.jpg', 'font!google,families:[Tangerine]']);
```
License
---
MIT
没有合适的资源?快使用搜索试试~ 我知道了~
OpenOKR:开源OKR管理软件

共929个文件
java:355个
js:285个
xml:62个

需积分: 48 35 下载量 46 浏览量
2021-04-28
09:46:54
上传
评论 1
收藏 3.3MB ZIP 举报
温馨提示
打开OKR 开源OKR管理软件 介绍 OpenOKR旨在解决从创业到公司的多管理问题。 建立战略与执行之间的一致性 浮现您的主要目标,他们引导工作和协调。 确保公司将精力集中在整个组织的相同重要问题上 支持自上而下和自下而上的OKR设置过程 贡献者 这些人为OpenOKR的设计和实施做出了贡献: 名称 角色 项目负责人 陈益宏 用户体验设计师 刘永兵 前端工程师 技术主管 后端工程师 质量检查工程师 执照 此项目已获得GNU GPL 3.0许可证的许可-有关详细信息,请参阅文件。
资源详情
资源评论
资源推荐
收起资源包目录





































































































共 929 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10




格式:pdf 资源大小:111.1KB 页数:5












格式:pdf 资源大小:1.2MB 页数:5


格式:pdf 资源大小:3.8MB 页数:94












蕾拉聊以色列
- 粉丝: 32
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 对机器学习的各个知识点进行系统梳理
- 基于微信小程序的培训机构全流程智能课时管理系统-学员端预约扣课-老师端排课管理-后台课时统计-课程预约登记-课时消耗查询-课时增减管理-预约记录导出-云函数数据库-腾讯云开发解决方.zip
- 机器学习所运用的各类技术方法解析
- 系统梳理机器学习的各个知识点
- 论互联网对民间艺术作品版权的影响之保护对策.docx
- 学生网络学习资源利用情况的个案调查与分析.docx
- 企业信息网络安全管控系统的研究设计.docx
- 北京市建设项目管理交通影响评价准则和要求.doc
- 以立法和技术控制相结合的方式加强网络媒体文化建设.docx
- PLC变频系统PPT演示.ppt
- 网络攻击常见手段及防范措施.ppt
- CAD技术的发展现状及未来前景精.doc
- 数字校园网络接入控制系统设计与实现.docx
- 电气控制与PLC应用陈建明第三版习题解答.doc
- Electron在企业IM前端工程实践.pdf
- 遗传算法在地下工程项目的参数反演中的应用.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

评论0