Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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')
}
})

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions test/expected-sf-static.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.foo {background: green}
2 changes: 1 addition & 1 deletion test/expected.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
._32de081b h1 {
h1 {
font-family: sans-serif;
}
16 changes: 16 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 3 additions & 0 deletions test/source-sf-static.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var insertCss = require('sheetify/insert')

insertCss('.foo {background: green}')