New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combo模式支持 #49

Closed
wants to merge 3 commits into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+76 −7
Diff settings

Always

Just for now

View
@@ -31,6 +31,20 @@ fis.match('::packager', {
});
```
## 使用combo
```
fis.match('::packager', {
postpackager: fis.plugin('loader', {
renderMode: {
'type': 'combo', //默认是tag
comboMaxFiles: 15, //最大combo文件
prefixer: '//xxxx??' //combo服务器地址,或者function
}
})
});
```
## 文件属性
新版本中所有 `isHtmlLike:true` 的资源都会默认采用 html 的方式来处理,比如: `.md`, `.tpl` 或者是更多。如果你希望某类 `isHtmlLike``true` 的资源,不经过此插件处理,那么请设置 `loaderLang` 属性为 `false`
@@ -41,6 +55,8 @@ fis.match('*.md', {
});
```
## 处理流程说明
如果你真的很关心的话,以下详细的流程处理介绍。
View
@@ -123,7 +123,11 @@ rudePackager.defaultOptions = {
// 资源占位符
resourcePlaceHolder: '<!--RESOURCEMAP_PLACEHOLDER-->',
renderMode: {
type: 'tag',
// 最大combo的文件数
comboMaxFiles: 15
},
// 资源表格式。
// 可选:
// - `auto` 根据用户选择的 js 来自动设置。
View
@@ -44,8 +44,8 @@ function obtainFramework(content, resource, opts, host) {
// 根据 js 自动设置 resourceType。
if (opts.resourceType === 'auto' && file) {
opts.resourceType = file.basename === 'mod.js' ? 'mod' :
(file.basename === 'sea.js' ? 'cmd' :
opts.resourceType = file.basename === 'mod.js' ? 'mod' :
(file.basename === 'sea.js' ? 'cmd' :
(file.basename === 'system.js' ? 'system' : 'amd'));
}
@@ -259,12 +259,16 @@ function process(file, resource, opts) {
var content = file.getContent();
var pool = [];
var list;
var comboUris = [];
var renderMode = opts.renderMode;
resource.calculate();
if (~content.indexOf(opts.stylePlaceHolder)) {
var css = [];
var lastItem;
comboUris.length = 0;
// 把分析到的 css 内容输出,同时合并挨在一起的内嵌脚本
if (resource.css.length) {
@@ -289,11 +293,34 @@ function process(file, resource, opts) {
if (item.id) {
fis.emit('plugin:relative:fetch', msg);
}
switch (renderMode.type) {
case 'combo':
if (comboUris.length >= renderMode.comboMaxFiles) {
if (typeof renderMode.prefixer === 'function') {
css.push(renderMode.prefixer(comboUris, 'css'));
} else {
css.push('<link rel="stylesheet" type="text/css" href="' + renderMode.prefixer + comboUris.join(',') + '"></script>');
}
comboUris.length = 0;
}
comboUris.push(msg.ret)
break;
default:
css.push('<link' + item.attrs + ' href="' + msg.ret + '" />');
}
css.push('<link' + item.attrs + ' href="' + msg.ret + '" />');
}
});
if (comboUris.length) {
if (typeof renderMode.prefixer === 'function') {
css.push(renderMode.prefixer(comboUris, 'css'));
} else {
css.push('<link rel="stylesheet" type="text/css" href="' + renderMode.prefixer + comboUris.join(',') + '"></script>');
}
}
if (pool.length) {
css.push('<style' + lastItem.attrs + '>' + pool.join('\n') + '</style>');
}
@@ -304,7 +331,7 @@ function process(file, resource, opts) {
if (~content.indexOf(opts.scriptPlaceHolder)) {
var js = [], lastItem;
comboUris.length = 0;
// 把分析到的 js 内容输出,同时合并挨在一起的内嵌脚本
if (resource.js.length) {
pool = [];
@@ -329,10 +356,32 @@ function process(file, resource, opts) {
fis.emit('plugin:relative:fetch', msg);
}
js.push('<script' + item.attrs + ' src="' + msg.ret + '"></script>');
switch (renderMode.type) {
case 'combo':
if (comboUris.length >= renderMode.comboMaxFiles) {
if (typeof renderMode.prefixer === 'function') {
js.push(renderMode.prefixer(comboUris, 'js'));
} else {
js.push('<script src="' + renderMode.prefixer + comboUris.join(',') + '"></script>');
}
comboUris.length = 0;
}
comboUris.push(msg.ret)
break;
default:
js.push('<script' + item.attrs + ' src="' + msg.ret + '"></script>');
}
}
});
if (comboUris.length) {
if (typeof renderMode.prefixer === 'function') {
js.push(renderMode.prefixer(comboUris, 'js'));
} else {
js.push('<script src="' + renderMode.prefixer + comboUris.join(',') + '"></script>');
}
}
if (pool.length) {
js.push('<script' + lastItem.attrs + '>' + pool.join('\n') + '</script>');
}
ProTip! Use n and p to navigate between commits in a pull request.