diff --git a/css-plugin-base-builder.js b/css-plugin-base-builder.js index 63261ea..9c6ba62 100644 --- a/css-plugin-base-builder.js +++ b/css-plugin-base-builder.js @@ -55,6 +55,7 @@ exports.bundle = function(loads, compileOpts, outputOpts) { return; var loader = this; + var importLoader; // backwards compat with fileURL for rootURL if (loader.rootURL && loader.rootURL.substr(0, 5) == 'file:') @@ -70,6 +71,7 @@ exports.bundle = function(loads, compileOpts, outputOpts) { var inputFiles = {}; cssLoads.forEach(function(load) { + importLoader = load.metadata.loader; inputFiles[path.relative(baseURLPath, fromFileURL(load.address))] = { source: load.metadata.style, sourceMap: load.metadata.styleSourceMap @@ -83,12 +85,34 @@ exports.bundle = function(loads, compileOpts, outputOpts) { } var cwd = process.cwd(); + var oldTranslate = importLoader.translate; + var oldImport = importLoader.import; + + importLoader.translate = function(load) { + return loader.translate.call(this, load).then(function() { + if(load.metadata.style) { + inputFiles[path.relative(baseURLPath, fromFileURL(load.address))] = { + source: load.metadata.style, + sourceMap: load.metadata.styleSourceMap + }; + load.metadata.format = 'amd'; + } + }); + }; + + importLoader.import = loader.import; var postCssPlugins = [atImport({ resolve: function(fileName, dirname, opts) { - if (absUrl(fileName)) - return fileName; - return path.relative(baseURLPath, path.join(dirname, fileName)); + var resolved = fileName; + if (!absUrl(fileName)) { + fileName = path.join(dirname, fileName); + resolved = path.relative(baseURLPath, fileName); + } + + return importLoader.import(fileName, module.id).then(function() { + return resolved; + }); }, load: function(fileName, opts) { if (absUrl(fileName)) @@ -158,6 +182,9 @@ exports.bundle = function(loads, compileOpts, outputOpts) { .then(function(result) { var cssOutput = result.css; + importLoader.translate = oldTranslate; + importLoader.import = oldImport; + // write a separate CSS file if necessary if (loader.separateCSS) { var outFile = path.resolve(outputOpts.outFile).replace(/\.js$/, '.css'); diff --git a/css-plugin-base.js b/css-plugin-base.js index 3d54c8f..9521d8e 100644 --- a/css-plugin-base.js +++ b/css-plugin-base.js @@ -16,6 +16,7 @@ function CSSPluginBase(compileCSS) { return Promise.resolve(compileCSS.call(loader, load.source, load.address, load.metadata.loaderOptions || {})) .then(function(result) { + Object.defineProperty(load.metadata, 'loader', { enumerable: false, value: loader }); load.metadata.style = result.css; load.metadata.styleSourceMap = result.map; if (result.moduleFormat)