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

Commit 874f4fe

Browse files
committed
Implement bundling files from @import statements.
1 parent 12e6185 commit 874f4fe

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

css-plugin-base-builder.js

+29-3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ exports.bundle = function(loads, compileOpts, outputOpts) {
7070

7171
var inputFiles = {};
7272
cssLoads.forEach(function(load) {
73+
loader.builder = load.metadata.builder;
7374
inputFiles[path.relative(baseURLPath, fromFileURL(load.address))] = {
7475
source: load.metadata.style,
7576
sourceMap: load.metadata.styleSourceMap
@@ -83,12 +84,35 @@ exports.bundle = function(loads, compileOpts, outputOpts) {
8384
}
8485

8586
var cwd = process.cwd();
87+
var translate = loader.translate;
88+
var instantiate = loader.instantiate;
89+
90+
loader.translate = function(load) {
91+
return translate.call(this, load).then(function() {
92+
if(load.metadata.style) {
93+
inputFiles[path.relative(baseURLPath, fromFileURL(load.address))] = {
94+
source: load.metadata.style,
95+
sourceMap: load.metadata.styleSourceMap
96+
};
97+
}
98+
});
99+
};
100+
101+
loader.instantiate = function(load) {};
86102

87103
var postCssPlugins = [atImport({
88104
resolve: function(fileName, dirname, opts) {
89-
if (absUrl(fileName))
90-
return fileName;
91-
return path.relative(baseURLPath, path.join(dirname, fileName));
105+
var resolved = fileName;
106+
if (!absUrl(fileName)) {
107+
fileName = path.join(dirname, fileName);
108+
resolved = path.relative(baseURLPath, fileName);
109+
}
110+
111+
return loader.import(fileName, module.id).then(function() {
112+
return resolved;
113+
}, function(err) {
114+
return resolved;
115+
});
92116
},
93117
load: function(fileName, opts) {
94118
if (absUrl(fileName))
@@ -157,6 +181,8 @@ exports.bundle = function(loads, compileOpts, outputOpts) {
157181
})
158182
.then(function(result) {
159183
var cssOutput = result.css;
184+
loader.translate = translate;
185+
loader.instantiate = instantiate;
160186

161187
// write a separate CSS file if necessary
162188
if (loader.separateCSS) {

css-plugin-base.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function CSSPluginBase(compileCSS) {
1616

1717
return Promise.resolve(compileCSS.call(loader, load.source, load.address, load.metadata.loaderOptions || {}))
1818
.then(function(result) {
19+
Object.defineProperty(load.metadata, 'builder', { enumerable: false, value: loader.builder });
1920
load.metadata.style = result.css;
2021
load.metadata.styleSourceMap = result.map;
2122
if (result.moduleFormat)

0 commit comments

Comments
 (0)