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
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,6 @@ css('normalize.css')
```
Packages from npm will not be namespaced by default.

## Toggle namespaces
To toggle namespaces for external files or npm packages:
```js
const css = require('sheetify')

css('./my-file.css', { global: true })
```
Be aware that when you toggle the namespace, the `:host` element matches won't
work anymore because the class it targets no longer exists. Only use this
toggle to write styles that are, well, global.

## Write to separate file on disk
To write the compiled CSS to a separate file, rather than keep it in the
bundle use [css-extract][2]:
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function parseCss (src, filename, prefix, options, done) {
applyTransforms(filename, String(src), xtend(options), function (err, css) {
if (err) return done(err)
var p = postcss()
if (options.global !== true) p = p.use(cssPrefix('.' + prefix))
p = p.use(cssPrefix('.' + prefix))

try {
css = p.process(css).toString()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"is-stream": "^1.0.1",
"map-limit": "0.0.1",
"postcss": "^5.0.10",
"postcss-prefix": "^1.0.3",
"postcss-prefix": "^2.0.0",
"resolve": "^1.1.7",
"stack-trace": "0.0.9",
"static-eval": "^0.2.4",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/plugins-expected.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
._08548a3e hello, ._08548a3e world {
._75161010 .hello,._75161010 .world {
-webkit-transform: translate(0, 0);
transform: translate(0, 0);
}
2 changes: 1 addition & 1 deletion test/fixtures/plugins-source.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const sf = require('sheetify')

const prefix = sf`
hello, world {
:host .hello, :host .world {
transform: translate(0, 0);
}
`
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/prefix-import-expected.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
._0081131d .foo {
._f918f624 .foo {
color: blue;
}
2 changes: 1 addition & 1 deletion test/fixtures/prefix-import-source.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.foo {
:host .foo {
color: blue;
}
2 changes: 1 addition & 1 deletion test/fixtures/prefix-inline-expected.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
._0081131d .foo {
._f918f624 .foo {
color: blue;
}
2 changes: 1 addition & 1 deletion test/fixtures/prefix-inline-source.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const sf = require('sheetify')

const prefix = sf`.foo {
const prefix = sf`:host .foo {
color: blue;
}
`
Expand Down
27 changes: 2 additions & 25 deletions test/prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ test('prefix', function (t) {
vm.runInNewContext(src.toString(), c)

function log (msg) {
t.equal(msg, '_0081131d', 'echoes prefix')
t.equal(msg, '_f918f624', 'echoes prefix')
}
}
})
Expand Down Expand Up @@ -94,31 +94,8 @@ test('prefix', function (t) {
vm.runInNewContext(src.toString(), c)

function log (msg) {
t.equal(msg, '_0081131d', 'echoes prefix')
t.equal(msg, '_f918f624', 'echoes prefix')
}
}
})

t.test('should disable prefixing when global:true', function (t) {
t.plan(1)

const expath = path.join(__dirname, 'fixtures/prefix-global-expected.css')
const expected = fs.readFileSync(expath, 'utf8').trim()

const ws = concat(function (buf) {
const res = String(buf).trim()
t.equal(res, expected, 'css is equal')
})

const bOpts = { browserField: false }
const bpath = path.join(__dirname, 'fixtures/prefix-global-source.js')
browserify(bpath, bOpts)
.transform(transform)
.plugin('css-extract', { out: outFn })
.bundle()

function outFn () {
return ws
}
})
})
8 changes: 3 additions & 5 deletions transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ function transform (filename, options) {
if (node.type !== 'CallExpression') return
if (!node.callee || node.callee.type !== 'Identifier') return
if (node.callee.name !== mname) return
const isLocalFile = /^\.{0,2}\//.test(node.arguments[0].value)
const localOptions = { global: !isLocalFile }
try {
var resolvePath = cssResolve(node.arguments[0].value, {
basedir: path.dirname(filename)
Expand All @@ -127,9 +125,9 @@ function transform (filename, options) {
return self.emit('error', err)
}

const iOpts = node.arguments[1]
? xtend(opts, localOptions, staticEval(node.arguments[1]))
: xtend(opts, localOptions)
const iOpts = (node.arguments[1])
? xtend(opts, staticEval(node.arguments[1]))
: opts

const val = {
filename: resolvePath,
Expand Down