Skip to content

Commit b73d520

Browse files
authored
Merge pull request #38 from hao123-fe/dev
fix css inline and release v0.1.5
2 parents 472adaf + 1af5c6e commit b73d520

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

configs/default.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var requireAnalyze = require("../plugins/requireAnalyze.js");
33
var jsWrapper = require("../plugins/jsWrapper.js");
44
var autoPackAnalyze = require("../plugins/autoPackAnalyze.js");
55
var outputHermap = require("../plugins/outputHermap.js");
6+
var cssInline = require("../plugins/cssInline.js");
67

78
//copy fis-plus default configs
89
module.exports = {
@@ -50,7 +51,8 @@ module.exports = {
5051
autoPackAnalyze,
5152
outputHermap
5253
],
53-
packager: null
54+
packager: [],
55+
postpackager: [ cssInline ]
5456
},
5557
// modules: {
5658
// parser: {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "her",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "A High-performence Enhanced Rendering solution - Hao123前端高性能渲染解决方案",
55
"keywords": [
66
"herJS",

plugins/cssInline.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* postpackager cssInline
3+
*
4+
* @author zhangwentao <zhangwentao@baidu.com>
5+
*/
6+
7+
module.exports = function(ret, conf, settings, opt) {
8+
fis.util.map(ret.map.her, function (herId) {
9+
var herRes = ret.map.her[herId];
10+
if (herRes.inline && herRes.file) {
11+
// console.log(herId);
12+
herRes.content = herRes.file.getContent();
13+
delete herRes.inline;
14+
delete herRes.file;
15+
}
16+
});
17+
};

plugins/outputHermap.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ var exports = module.exports = function (ret, conf, settings, opt) {
4141
fis.util.map(conf, function (path, patterns, index) {
4242
var pid, subpath, pkg;
4343
var needInline = false;
44-
var inlineReg = /\?__inline/;
44+
var INLINE_REG = /\?__inline/;
45+
46+
if (INLINE_REG.test(path)) {
47+
needInline = true;
48+
path = path.replace(INLINE_REG, '');
49+
}
50+
4551
if (typeof patterns === 'string' || patterns instanceof RegExp) {
4652
patterns = [patterns];
4753
}
4854
if (fis.util.is(patterns, 'Array') && patterns.length) {
49-
pid = 'p' + index;
50-
51-
if (inlineReg.test(path)) {
52-
needInline = true;
53-
path = path.replace(inlineReg, '');
54-
}
55-
55+
pid = 'p' + index;
5656
subpath = path.replace(/^\//, '');
5757
pkg = fis.file(root, subpath);
5858
if (typeof ret.src[pkg.subpath] !== 'undefined') {
@@ -144,6 +144,7 @@ var exports = module.exports = function (ret, conf, settings, opt) {
144144
}
145145
});
146146
});
147+
147148
if (defines.length) {
148149
pkg.file.setContent(content);
149150
ret.pkg[pkg.file.subpath] = pkg.file;
@@ -182,9 +183,11 @@ var exports = module.exports = function (ret, conf, settings, opt) {
182183
herRes.defines = defines;
183184
herRes.requires = deps;
184185
herRes.requireAsyncs = asyncs;
185-
186+
187+
// for cssInline
186188
if (pkg.inline) {
187-
herRes.content = content;
189+
herRes.inline = true;
190+
herRes.file = pkg.file;
188191
}
189192
}
190193
});

0 commit comments

Comments
 (0)