diff --git a/index.js b/index.js index cb88fe9..c5e6154 100644 --- a/index.js +++ b/index.js @@ -32,7 +32,7 @@ function cssExtract (bundle, opts) { function write (chunk, enc, cb) { // Performance boost: don't do ast parsing unless we know it's needed - if (String(chunk.source).indexOf('insert-css') === -1) { + if (!/[insert\-css|sheetify\/insert]/.test(chunk.source)) { return cb(null, chunk) } @@ -41,6 +41,10 @@ function cssExtract (bundle, opts) { 'insert-css': function (src) { writeStream.write(String(src) + '\n') return from2('null') + }, + 'sheetify/insert': function (src) { + writeStream.write(String(src) + '\n') + return from2('null') } }) diff --git a/package.json b/package.json index d58e988..2c3f785 100644 --- a/package.json +++ b/package.json @@ -28,9 +28,9 @@ "devDependencies": { "browserify": "^13.0.0", "dependency-check": "^2.5.1", - "insert-css": "^0.2.0", + "insert-css": "^2.0.0", "istanbul": "^0.4.2", - "sheetify": "^4.1.0", + "sheetify": "^6.0.0", "standard": "^6.0.7", "tape": "^4.5.0", "tmp": "0.0.28" diff --git a/test/expected-sf-static.css b/test/expected-sf-static.css new file mode 100644 index 0000000..6033a3c --- /dev/null +++ b/test/expected-sf-static.css @@ -0,0 +1 @@ +.foo {background: green} diff --git a/test/expected.css b/test/expected.css index e674983..43a9ee3 100644 --- a/test/expected.css +++ b/test/expected.css @@ -1,3 +1,3 @@ -._32de081b h1 { +h1 { font-family: sans-serif; } diff --git a/test/index.js b/test/index.js index 7a19357..1afa789 100644 --- a/test/index.js +++ b/test/index.js @@ -71,6 +71,22 @@ test('css-extract', function (t) { } }) + t.test('should extract static sheetify/insert statements', function (t) { + t.plan(2) + browserify(path.join(__dirname, 'source-sf-static.js')) + .plugin(cssExtract, { out: createWs }) + .bundle() + + function createWs () { + return bl(function (err, data) { + t.ifError(err, 'no error') + const exPath = path.join(__dirname, './expected-sf-static.css') + const expected = fs.readFileSync(exPath, 'utf8').trim() + '\n' + t.equal(String(data), expected, 'extracted all the CSS') + }) + } + }) + t.test('should not extract dynamic insert-css statements', function (t) { t.plan(4) const sourcePath = path.join(__dirname, 'source-dynamic.js') diff --git a/test/source-sf-static.js b/test/source-sf-static.js new file mode 100644 index 0000000..6242da9 --- /dev/null +++ b/test/source-sf-static.js @@ -0,0 +1,3 @@ +var insertCss = require('sheetify/insert') + +insertCss('.foo {background: green}')