Skip to content
Open
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: 14 additions & 0 deletions css-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var concat = require('concat-stream');
var findNodeModules = require('find-node-modules');
var mime = require('mime');
var stripComments = require('strip-css-comments');
var resolve = require("resolve");

var isExternalURL = function(path) {
return !! url.parse(path).protocol;
Expand All @@ -22,6 +23,17 @@ var isNodeModulePath = function(path) {
return /^node_modules/.test(path);
};

// Finds the the import path from parent node_modules even if node_modules is not prefixed in the path
// @see {@link https://github.com/cheton/browserify-css/issues/46} for further information.
var isImplicitNodeModulePath = function(url, dirname) {
try {
var newpathname = resolve.sync(url, { basedir: dirname });
return newpathname;
} catch (error) {
return false;
}
};

// Finds the the import path from parent node_modules.
// @see {@link https://github.com/cheton/browserify-css/pull/21} for further information.
var findImportPathInNodeModules = function(baseDir, importPath) {
Expand Down Expand Up @@ -249,6 +261,8 @@ var cssTransform = function(options, filename, callback) {
// in case it was deduped to a higher location in the tree
if (isNodeModulePath(url)) {
pathname = findImportPathInNodeModules(dirname, url);
} else if (data = isImplicitNodeModulePath(url, dirname)) { // direct requiring of node modules
pathname = data;
} else if (isRelativePath(url)) { // relative path
pathname = path.resolve(dirname, url);
} else { // absolute path
Expand Down
1 change: 1 addition & 0 deletions examples/submodules/app.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import "../node_modules/bootstrap/dist/css/bootstrap.css";
@import "bootstrap/dist/css/bootstrap-theme.css";
@import "modules/foo/foo.css";
@import "modules/bar/bar.css";
39 changes: 0 additions & 39 deletions examples/submodules/bundle.js

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"find-node-modules": "^2.0.0",
"lodash": "^4.17.11",
"mime": "^1.3.6",
"resolve": "^1.20.0",
"strip-css-comments": "^3.0.0",
"through2": "2.0.x"
},
Expand Down