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

Commit 71ca94d

Browse files
committed
Implement bundling files from @import statements.
1 parent 12e6185 commit 71ca94d

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

css-plugin-base-builder.js

Lines changed: 24 additions & 3 deletions
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,31 @@ exports.bundle = function(loads, compileOpts, outputOpts) {
8384
}
8485

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

87101
var postCssPlugins = [atImport({
88102
resolve: function(fileName, dirname, opts) {
89-
if (absUrl(fileName))
90-
return fileName;
91-
return path.relative(baseURLPath, path.join(dirname, fileName));
103+
var resolved = fileName;
104+
if (!absUrl(fileName)) {
105+
fileName = path.join(dirname, fileName);
106+
resolved = path.relative(baseURLPath, fileName);
107+
}
108+
109+
return loader.import(fileName, module.id).then(function() {
110+
return resolved;
111+
});
92112
},
93113
load: function(fileName, opts) {
94114
if (absUrl(fileName))
@@ -157,6 +177,7 @@ exports.bundle = function(loads, compileOpts, outputOpts) {
157177
})
158178
.then(function(result) {
159179
var cssOutput = result.css;
180+
loader.translate = translate;
160181

161182
// write a separate CSS file if necessary
162183
if (loader.separateCSS) {

css-plugin-base.js

Lines changed: 1 addition & 0 deletions
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)