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
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ const tree = html`
document.body.appendChild(tree)
```

Compile with browserify using `-t sheetify/transform`:
Compile with browserify using `-t sheetify`:
```sh
$ browserify -t sheetify/transform index.js > bundle.js
$ browserify -t sheetify index.js > bundle.js
```

CSS classes are namespaced based on the content hash:
Expand Down Expand Up @@ -133,7 +133,7 @@ To write the compiled CSS to a separate file, rather than keep it in the
bundle use [css-extract][2]:
```sh
$ browserify index.js \
-t [ sheetify/transform ] \
-t [ sheetify ] \
-p [ css-extract -o bundle.css ] index.js \
-o bundle.js
```
Expand Down Expand Up @@ -164,9 +164,9 @@ const tree = html`
document.body.appendChild(tree)
```

Compile with browserify using `-t [ sheetify/transform -u sheetify-cssnext ]`:
Compile with browserify using `-t [ sheetify -u sheetify-cssnext ]`:
```sh
$ browserify -t [ sheetify/transform -u sheetify-cssnext ] index.js > bundle.js
$ browserify -t [ sheetify -u sheetify-cssnext ] index.js > bundle.js
```

Transforms the CSS into:
Expand All @@ -185,7 +185,7 @@ The following plugins are available:
Browserify transforms accept either flags from the command line using
[subargs](https://github.com/substack/subarg):
```sh
$ browserify -t [ sheetify/transform -u sheetify-cssnext ] index.js > bundle.js
$ browserify -t [ sheetify -u sheetify-cssnext ] index.js > bundle.js
```

Or the equivalent options by passing in a configuration object in the
Expand All @@ -194,7 +194,7 @@ JavaScript API:
const browserify = require('browserify')

const b = browserify(path.join(__dirname, 'transform/source.js'))
b.transform('sheetify/transform', { use: [ 'sheetify-cssnext' ] })
b.transform('sheetify', { use: [ 'sheetify-cssnext' ] })
b.bundle().pipe(process.stdout)
```

Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ module.exports.getPrefix = getPrefix
// transform css
// (str, str, obj?, fn) -> str
function sheetify (src, filename, options, done) {
// browserify transform
if (typeof src === 'string' && !/\n/.test(src) && filename && filename._flags) {
var args = Array.prototype.slice.apply(arguments)
return require('./transform.js').apply(this, args)
}

// handle tagged template calls directly from Node
const isTemplate = Array.isArray(src)
if (isTemplate) src = src.join('')
Expand Down
2 changes: 1 addition & 1 deletion test/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const test = require('tape')
const path = require('path')
const fs = require('fs')

const sheetify = require(path.join(__dirname, '../transform'))
const sheetify = require('../')

test('npm import', function (t) {
t.test('should import npm packages', function (t) {
Expand Down
4 changes: 2 additions & 2 deletions test/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ const test = require('tape')
const join = require('path').join
const browserify = require('browserify')

const transform = require('../transform')
const sheetify = require('..')

test('JSON files', function (t) {
t.plan(2)

browserify()
.add(join(__dirname, 'fixtures', './example.json'))
.transform(transform)
.transform(sheetify)
.bundle(function (err, code) {
if (err) return t.end(err)
code = String(code)
Expand Down
2 changes: 1 addition & 1 deletion test/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const test = require('tape')
const path = require('path')
const fs = require('fs')

const sheetify = require(path.join(__dirname, '../transform'))
const sheetify = require('../')

test('plugins', function (t) {
t.test('should transform CSS', function (t) {
Expand Down
5 changes: 2 additions & 3 deletions test/prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const fs = require('fs')
const vm = require('vm')
const cssResolve = require('style-resolve').sync

const transform = require('../transform')
const sheetify = require('..')

test('prefix', function (t) {
Expand Down Expand Up @@ -48,7 +47,7 @@ test('prefix', function (t) {
const bOpts = { browserField: false }
const bpath = path.join(__dirname, 'fixtures/prefix-inline-source.js')
browserify(bpath, bOpts)
.transform(transform)
.transform(sheetify)
.transform(function (file) {
return through(function (buf, enc, next) {
const str = buf.toString('utf8')
Expand Down Expand Up @@ -88,7 +87,7 @@ test('prefix', function (t) {
const bOpts = { browserField: false }
const bpath = path.join(__dirname, 'fixtures/prefix-import-source.js')
browserify(bpath, bOpts)
.transform(transform)
.transform(sheetify)
.transform(function (file) {
return through(function (buf, enc, next) {
const str = buf.toString('utf8')
Expand Down