From 1af5c6e3d4ba703869a89f7faca2ac08b1a2b96e Mon Sep 17 00:00:00 2001 From: zhangwentao Date: Mon, 14 Nov 2016 16:38:33 +0800 Subject: [PATCH] fix css inline and release v0.1.5 - fix css inline and release v0.1.5 --- configs/default.js | 4 +++- package.json | 2 +- plugins/cssInline.js | 17 +++++++++++++++++ plugins/outputHermap.js | 23 +++++++++++++---------- 4 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 plugins/cssInline.js diff --git a/configs/default.js b/configs/default.js index 70ca8da..0ea0331 100644 --- a/configs/default.js +++ b/configs/default.js @@ -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 = { @@ -50,7 +51,8 @@ module.exports = { autoPackAnalyze, outputHermap ], - packager: null + packager: [], + postpackager: [ cssInline ] }, // modules: { // parser: { diff --git a/package.json b/package.json index d304b4b..484b769 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "her", - "version": "0.1.4", + "version": "0.1.5", "description": "A High-performence Enhanced Rendering solution - Hao123前端高性能渲染解决方案", "keywords": [ "herJS", diff --git a/plugins/cssInline.js b/plugins/cssInline.js new file mode 100644 index 0000000..687cd88 --- /dev/null +++ b/plugins/cssInline.js @@ -0,0 +1,17 @@ +/** + * postpackager cssInline + * + * @author zhangwentao + */ + +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; + } + }); +}; \ No newline at end of file diff --git a/plugins/outputHermap.js b/plugins/outputHermap.js index 49a6549..10043c9 100644 --- a/plugins/outputHermap.js +++ b/plugins/outputHermap.js @@ -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') { @@ -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; @@ -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; } } });