diff --git a/index.js b/index.js index cfbfdac..61c17fa 100644 --- a/index.js +++ b/index.js @@ -73,7 +73,7 @@ module.exports = function (browserify, options) { // bundles var sourceByFile = {}; - browserify.transform(function transform (filename) { + function transform (filename) { // only handle .css files if (!cssExt.test(filename)) { return through(); @@ -104,6 +104,10 @@ module.exports = function (browserify, options) { console.error(err); }); }); + } + + browserify.transform(transform, { + global: true }); // wrap the `bundle` function diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..cf4bab9 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +!node_modules diff --git a/tests/cases/import-node-module/expected.css b/tests/cases/import-node-module/expected.css new file mode 100644 index 0000000..f0a88f9 --- /dev/null +++ b/tests/cases/import-node-module/expected.css @@ -0,0 +1,3 @@ +._styles__foo { + color: #F00; +} diff --git a/tests/cases/import-node-module/main.js b/tests/cases/import-node-module/main.js new file mode 100644 index 0000000..59f8d0d --- /dev/null +++ b/tests/cases/import-node-module/main.js @@ -0,0 +1 @@ +var styles = require('cool-styles/styles.css'); diff --git a/tests/cases/import-node-module/node_modules/cool-styles/styles.css b/tests/cases/import-node-module/node_modules/cool-styles/styles.css new file mode 100644 index 0000000..092b8ad --- /dev/null +++ b/tests/cases/import-node-module/node_modules/cool-styles/styles.css @@ -0,0 +1,3 @@ +.foo { + color: #F00; +}