browserify-css
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -13,3 +13,3 @@ 'use strict'; | ||
return !! url.parse(path).protocol; | ||
} | ||
}; | ||
@@ -42,7 +42,7 @@ var isRelativePath = function(path) { | ||
var r; | ||
while (r = urlRegEx.exec(source)) { | ||
var url = r[2] // url("path/to/foo.css"); | ||
|| r[3] // url('path/to/foo.css'); | ||
|| r[1] // url(path/to/foo.css) | ||
|| ''; | ||
while ((r = urlRegEx.exec(source))) { | ||
var url = r[2] || // url("path/to/foo.css"); | ||
r[3] || // url('path/to/foo.css'); | ||
r[1] || // url(path/to/foo.css) | ||
''; | ||
var quoteLen = ((r[2] || r[3]) && r[1]) ? 1 : 0; | ||
@@ -53,3 +53,3 @@ var newUrl = url; | ||
// if both r[2] and r[3] are undefined, but r[1] is a string, it will be the case of url(path/to/foo.css) | ||
var quoteLen = ((r[2] || r[3]) && r[1]) ? 1 : 0; | ||
quoteLen = ((r[2] || r[3]) && r[1]) ? 1 : 0; | ||
@@ -78,3 +78,2 @@ var dirname = path.dirname(filename); | ||
_.each(rules, function(rule) { | ||
if (rule.type === 'import') { | ||
@@ -91,11 +90,11 @@ // | ||
var importRegEx = /(url)?\s*(('([^']*)'|"([^"]*)")|\(('([^']*)'|"([^"]*)"|([^\)]*))\))\s*;?/; | ||
var result = importRegEx.exec(rule.import); | ||
var result = importRegEx.exec(rule['import']); | ||
// rule.import result array | ||
// ======================================= | ||
var url = result[7] // url('path/to/foo.css') result[7] = path/to/foo.css | ||
|| result[8] // url("path/to/foo.css") result[8] = path/to/foo.css | ||
|| result[9] // url(path/to/foo.css) result[9] = path/to/foo.css | ||
|| result[4] // 'path/to/foo.css' result[4] = path/to/foo.css | ||
|| result[5]; // "path/to/foo.css" result[5] = path/to/foo.css | ||
// rule.import result array | ||
// ======================================= | ||
var url = result[7] || // url('path/to/foo.css') result[7] = path/to/foo.css | ||
result[8] || // url("path/to/foo.css") result[8] = path/to/foo.css | ||
result[9] || // url(path/to/foo.css) result[9] = path/to/foo.css | ||
result[4] || // 'path/to/foo.css' result[4] = path/to/foo.css | ||
result[5]; // "path/to/foo.css" result[5] = path/to/foo.css | ||
@@ -125,3 +124,3 @@ url = _str.trim(url); | ||
var result = css.stringify({ | ||
var css = css.stringify({ | ||
stylesheet: { | ||
@@ -131,4 +130,3 @@ rules: [ rule ] | ||
}); | ||
cssStream.write(result + '\n'); | ||
cssStream.write(css + '\n'); | ||
} | ||
@@ -135,0 +133,0 @@ }); |
20
index.js
@@ -22,11 +22,11 @@ 'use strict'; | ||
var pkg = JSON.parse(fs.readFileSync(process.cwd() + '/package.json') || '{}'); | ||
var options = pkg['browserify-css'] || {}; | ||
if (typeof options === 'string') { | ||
var base = path.relative(__dirname, process.cwd()); | ||
try { | ||
try { | ||
var pkg = JSON.parse(fs.readFileSync(process.cwd() + '/package.json') || '{}'); | ||
var options = pkg['browserify-css'] || defaults; | ||
if (typeof options === 'string') { | ||
var base = path.relative(__dirname, process.cwd()); | ||
options = require(path.join(base, options)) || defaults; | ||
} catch (err) { | ||
options = defaults; | ||
} | ||
} catch (err) { | ||
options = defaults; | ||
} | ||
@@ -65,8 +65,8 @@ options = _.defaults(options, defaults); | ||
if ( ! options['autoInject']) { | ||
moduleBody = 'module.exports = ' + JSON.stringify(data) + ';' | ||
moduleBody = 'module.exports = ' + JSON.stringify(data) + ';'; | ||
} else { | ||
if (options.autoInjectOptions['verbose']) { | ||
moduleBody = 'var css = ' + JSON.stringify(data) + '; (require(' + JSON.stringify(__dirname) + ').createStyle(css, { "href": ' + JSON.stringify(href) + '})); module.exports = css;' | ||
moduleBody = 'var css = ' + JSON.stringify(data) + '; (require(' + JSON.stringify(__dirname) + ').createStyle(css, { "href": ' + JSON.stringify(href) + '})); module.exports = css;'; | ||
} else { | ||
moduleBody = 'var css = ' + JSON.stringify(data) + '; (require(' + JSON.stringify(__dirname) + ').createStyle(css)); module.exports = css;' | ||
moduleBody = 'var css = ' + JSON.stringify(data) + '; (require(' + JSON.stringify(__dirname) + ').createStyle(css)); module.exports = css;'; | ||
} | ||
@@ -73,0 +73,0 @@ } |
{ | ||
"name": "browserify-css", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "A Browserify transform for bundling, rebasing, inlining, and minifying CSS files", | ||
@@ -8,3 +8,5 @@ "main": "./index.js", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "npm run gulp", | ||
"gulp": "gulp", | ||
"tap-test": "tap test/*.js" | ||
}, | ||
@@ -37,3 +39,7 @@ "repository": { | ||
"devDependencies": { | ||
"browserify": "6.3.x" | ||
"browserify": "^8.1.3", | ||
"gulp": "^3.8.11", | ||
"gulp-jshint": "^1.9.2", | ||
"jsdom": "^3.1.1", | ||
"tap": "^0.6.0" | ||
}, | ||
@@ -40,0 +46,0 @@ "bugs": { |
@@ -1,3 +0,5 @@ | ||
# browserify-css # | ||
# browserify-css [](https://travis-ci.org/cheton/browserify-css) | ||
[](https://nodei.co/npm/browserify-css/) | ||
A Browserify transform for bundling, rebasing, inlining, and minifying CSS files. It's useful for CSS modularization where styles are scoped to their related bundles. | ||
@@ -4,0 +6,0 @@ |
33830
21
694
128
5
7