Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Commit

Permalink
Implement bundling files from @import statements.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjrv committed May 2, 2018
1 parent 12e6185 commit 69148b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
25 changes: 22 additions & 3 deletions css-plugin-base-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ exports.bundle = function(loads, compileOpts, outputOpts) {
return;

var loader = this;
var importLoader = new loader.constructor();

// backwards compat with fileURL for rootURL
if (loader.rootURL && loader.rootURL.substr(0, 5) == 'file:')
Expand All @@ -70,6 +71,7 @@ exports.bundle = function(loads, compileOpts, outputOpts) {

var inputFiles = {};
cssLoads.forEach(function(load) {
importLoader.builder = load.metadata.builder;
inputFiles[path.relative(baseURLPath, fromFileURL(load.address))] = {
source: load.metadata.style,
sourceMap: load.metadata.styleSourceMap
Expand All @@ -84,11 +86,28 @@ exports.bundle = function(loads, compileOpts, outputOpts) {

var cwd = process.cwd();

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
};
}
});
};

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))
Expand Down
1 change: 1 addition & 0 deletions css-plugin-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, 'builder', { enumerable: false, value: loader.builder });
load.metadata.style = result.css;
load.metadata.styleSourceMap = result.map;
if (result.moduleFormat)
Expand Down

0 comments on commit 69148b2

Please sign in to comment.