diff --git a/css-transform.js b/css-transform.js index 54601bc..e6b54a3 100644 --- a/css-transform.js +++ b/css-transform.js @@ -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; @@ -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) { @@ -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 diff --git a/examples/submodules/app.css b/examples/submodules/app.css index 1835e7e..723ac40 100644 --- a/examples/submodules/app.css +++ b/examples/submodules/app.css @@ -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"; diff --git a/examples/submodules/bundle.js b/examples/submodules/bundle.js deleted file mode 100644 index b2facf5..0000000 --- a/examples/submodules/bundle.js +++ /dev/null @@ -1,39 +0,0 @@ -(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o