stylus-loader
Advanced tools
Comparing version 0.1.1 to 0.2.0
42
index.js
var loaderUtils = require('loader-utils'); | ||
var stylus = require('stylus'); | ||
var nib = require('nib'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
module.exports = function(source) { | ||
var self = this; | ||
this.cacheable && this.cacheable(); | ||
@@ -12,2 +15,3 @@ var done = this.async(); | ||
var styl = stylus(source); | ||
var paths = [path.dirname(options.filename)]; | ||
@@ -19,5 +23,7 @@ function needsArray(value) { | ||
if (options.paths && !Array.isArray(options.paths)) { | ||
paths = paths.concat(options.paths); | ||
options.paths = [options.paths]; | ||
} | ||
var manualImports = []; | ||
Object.keys(options).forEach(function(key) { | ||
@@ -38,2 +44,3 @@ var value = options[key]; | ||
styl.import(stylusModule); | ||
manualImports.push(stylusModule); | ||
}); | ||
@@ -45,4 +52,20 @@ } else { | ||
// TODO call this.addDependency for each imported stylus file | ||
// to fix watch mode | ||
extractImports(source).concat(manualImports).map(function(dep) { | ||
var filepath = null; | ||
for (var i = 0; i < paths.length; i++) { | ||
filepath = path.resolve(paths[i], dep); | ||
if (!fs.existsSync(filepath)) { | ||
filepath = path.resolve(paths[i], dep + '.styl'); | ||
if (fs.existsSync(filepath)) break; | ||
} else { | ||
break; | ||
} | ||
} | ||
return fs.existsSync(filepath) ? filepath : null; | ||
}).filter(function(dep) { | ||
return !!dep; | ||
}).forEach(function(dep) { | ||
self.addDependency(dep); | ||
}); | ||
styl.use(nib()); | ||
@@ -54,1 +77,16 @@ styl.render(function(err, css) { | ||
} | ||
// Not the best way but it works for now | ||
function extractImports(source) { | ||
var imports = []; | ||
var regex = /@import *[\'|\"]([^\'|\"]+)*/gi; | ||
var matches = regex.exec(source); | ||
if (matches) { | ||
imports.push(matches[1]); | ||
while (matches != null) { | ||
matches = regex.exec(source); | ||
if (matches) imports.push(matches[1]); | ||
} | ||
} | ||
return imports || []; | ||
} |
{ | ||
"name": "stylus-loader", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Stylus loader for webpack", | ||
@@ -19,4 +19,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"stylus": "~0.39.4", | ||
"nib": "~1.0.1", | ||
"stylus": "~0.42.2", | ||
"nib": "~1.0.2", | ||
"loader-utils": "~0.2.1" | ||
@@ -23,0 +23,0 @@ }, |
@@ -46,2 +46,3 @@ # stylus-loader | ||
## Release History | ||
* 0.2.0 - Now tracks dependencies for @import statements making cacheable work | ||
* 0.1.0 - Initial release | ||
@@ -48,0 +49,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7154
113
51
1
+ Addedstylus@0.42.3(transitive)
- Removedcssom@0.2.5(transitive)
- Removedstylus@0.39.4(transitive)
Updatednib@~1.0.2
Updatedstylus@~0.42.2