From 664fa34530c9ba25d5254abac16f4ba08efae822 Mon Sep 17 00:00:00 2001 From: aui <1987.tangbin@gmail.com> Date: Mon, 29 Dec 2014 19:44:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3CSS=20@import=20=E5=A4=9A?= =?UTF-8?q?=E7=A7=8D=E8=AF=AD=E6=B3=95=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/optimizer.js | 7 ++++++- src/spider.js | 9 ++++++++- test/css/g2.css | 0 test/css/ui.css | 1 + 5 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 test/css/g2.css diff --git a/package.json b/package.json index a10844b..c0f5346 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "font-spider", "description": "Font optimizer", - "version": "0.0.2", + "version": "0.0.3", "homepage": "https://github.com/aui/font-spider", "author": { "name": "aui", diff --git a/src/optimizer.js b/src/optimizer.js index e237664..2ccb5f9 100644 --- a/src/optimizer.js +++ b/src/optimizer.js @@ -74,7 +74,12 @@ Optimizer.prototype.minify = function (dest, chars) { // result.output - fs.renameSync(temp, dest); + if (fs.existsSync(temp)) { + fs.renameSync(temp, dest); + } else { + console.error('error', result.output); + } + } fs.unlinkSync(charsfile); diff --git a/src/spider.js b/src/spider.js index 6737cb7..67706da 100644 --- a/src/spider.js +++ b/src/spider.js @@ -279,7 +279,14 @@ Spider.prototype = { case 'import': RE_URL.lastIndex = 0; - var url = RE_URL.exec(rule['import'])[1]; + var url = rule['import']; + + // @import url("./g.css?t=2009"); + // @import "./g.css?t=2009"; + if (/url/i.test(url)) { + url = RE_URL.exec(url)[1]; + } + url = url.replace(RE_QUERY, ''); if (!RE_SERVER.test(url)) { diff --git a/test/css/g2.css b/test/css/g2.css new file mode 100644 index 0000000..e69de29 diff --git a/test/css/ui.css b/test/css/ui.css index 01dd5f3..71bd479 100644 --- a/test/css/ui.css +++ b/test/css/ui.css @@ -2,6 +2,7 @@ /** Reset */ @import url("./g.css?t=2009"); +@import "./g2.css"; @font-face { font-family: 'art'; /*IE*/