Skip to content

Commit

Permalink
Merge pull request #38 from hao123-fe/dev
Browse files Browse the repository at this point in the history
fix css inline and release v0.1.5
  • Loading branch information
allen-zh authored Nov 14, 2016
2 parents 472adaf + 1af5c6e commit b73d520
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
4 changes: 3 additions & 1 deletion configs/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var requireAnalyze = require("../plugins/requireAnalyze.js");
var jsWrapper = require("../plugins/jsWrapper.js");
var autoPackAnalyze = require("../plugins/autoPackAnalyze.js");
var outputHermap = require("../plugins/outputHermap.js");
var cssInline = require("../plugins/cssInline.js");

//copy fis-plus default configs
module.exports = {
Expand Down Expand Up @@ -50,7 +51,8 @@ module.exports = {
autoPackAnalyze,
outputHermap
],
packager: null
packager: [],
postpackager: [ cssInline ]
},
// modules: {
// parser: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "her",
"version": "0.1.4",
"version": "0.1.5",
"description": "A High-performence Enhanced Rendering solution - Hao123前端高性能渲染解决方案",
"keywords": [
"herJS",
Expand Down
17 changes: 17 additions & 0 deletions plugins/cssInline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* postpackager cssInline
*
* @author zhangwentao <[email protected]>
*/

module.exports = function(ret, conf, settings, opt) {
fis.util.map(ret.map.her, function (herId) {
var herRes = ret.map.her[herId];
if (herRes.inline && herRes.file) {
// console.log(herId);
herRes.content = herRes.file.getContent();
delete herRes.inline;
delete herRes.file;
}
});
};
23 changes: 13 additions & 10 deletions plugins/outputHermap.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ var exports = module.exports = function (ret, conf, settings, opt) {
fis.util.map(conf, function (path, patterns, index) {
var pid, subpath, pkg;
var needInline = false;
var inlineReg = /\?__inline/;
var INLINE_REG = /\?__inline/;

if (INLINE_REG.test(path)) {
needInline = true;
path = path.replace(INLINE_REG, '');
}

if (typeof patterns === 'string' || patterns instanceof RegExp) {
patterns = [patterns];
}
if (fis.util.is(patterns, 'Array') && patterns.length) {
pid = 'p' + index;

if (inlineReg.test(path)) {
needInline = true;
path = path.replace(inlineReg, '');
}

pid = 'p' + index;
subpath = path.replace(/^\//, '');
pkg = fis.file(root, subpath);
if (typeof ret.src[pkg.subpath] !== 'undefined') {
Expand Down Expand Up @@ -144,6 +144,7 @@ var exports = module.exports = function (ret, conf, settings, opt) {
}
});
});

if (defines.length) {
pkg.file.setContent(content);
ret.pkg[pkg.file.subpath] = pkg.file;
Expand Down Expand Up @@ -182,9 +183,11 @@ var exports = module.exports = function (ret, conf, settings, opt) {
herRes.defines = defines;
herRes.requires = deps;
herRes.requireAsyncs = asyncs;


// for cssInline
if (pkg.inline) {
herRes.content = content;
herRes.inline = true;
herRes.file = pkg.file;
}
}
});
Expand Down

0 comments on commit b73d520

Please sign in to comment.