Skip to content

Commit 94ff62b

Browse files
committed
fix the build when clean-css is missing
1 parent 554f640 commit 94ff62b

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

css.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ define([
172172
* and writes it to the modules layer.
173173
* @param {string} dest - Current css layer path.
174174
* @param {Array} loadList - List of css files contained in current css layer.
175+
* @returns {boolean} Return `true` if the function successfully writes the layer.
175176
*/
176177
writeLayer: function (writePluginFiles, dest, loadList) {
177178
function tryRequire(paths) {
@@ -190,18 +191,19 @@ define([
190191

191192
var path = require.getNodePath(require.toUrl(module.id).replace(/[^\/]*$/, "node_modules/clean-css"));
192193
var CleanCSS = tryRequire([path, "clean-css"]);
194+
var fs = require.nodeRequire("fs");
195+
196+
loadList = loadList.map(require.toUrl)
197+
.filter(function (path) {
198+
if (!fs.existsSync(path)) {
199+
console.log(">> Css file '" + path + "' was not found.");
200+
return false;
201+
}
202+
return true;
203+
});
193204

194205
if (CleanCSS) {
195206
var result = "";
196-
loadList = loadList.map(require.toUrl)
197-
.filter(function (path) {
198-
var fs = require.nodeRequire("fs");
199-
if (!fs.existsSync(path)) {
200-
console.log(">> Css file '" + path + "' was not found.");
201-
return false;
202-
}
203-
return true;
204-
});
205207
loadList.forEach(function (src) {
206208
result += new CleanCSS({
207209
relativeTo: "./",
@@ -210,9 +212,14 @@ define([
210212
});
211213

212214
writePluginFiles(dest, result);
215+
return true;
213216
} else {
214217
console.log(">> Node module clean-css not found. Skipping CSS inlining. If you want CSS inlining" +
215218
" run 'npm install clean-css' in your console.");
219+
loadList.forEach(function (src) {
220+
writePluginFiles(src, fs.readFileSync(src));
221+
});
222+
return false;
216223
}
217224
},
218225

@@ -238,9 +245,9 @@ define([
238245
var destMid = data.name.replace(/^(([^\/]*\/)*)[^\/]*$/, "$1css/layer.css");
239246

240247
// Write layer file
241-
buildFunctions.writeLayer(writePluginFiles, dest, loadList);
242-
// Write css config on the layer
243-
buildFunctions.writeConfig(write, module.id, destMid, loadList);
248+
var success = buildFunctions.writeLayer(writePluginFiles, dest, loadList);
249+
// Write css config on the layer if the layer was successfully written.
250+
success && buildFunctions.writeConfig(write, module.id, destMid, loadList);
244251
// Reset loadList
245252
loadList = [];
246253
}

0 commit comments

Comments
 (0)