Skip to content

Commit

Permalink
Exclude external resources from r.js optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
dchekanov committed Jan 5, 2016
1 parent 3b1d868 commit 11d0459
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions css-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ define(['require', './normalize'], function(req, normalize) {
if (config.optimizeCss == 'none') {
return css;
}

if (typeof process !== "undefined" && process.versions && !!process.versions.node && require.nodeRequire) {
try {
var csso = require.nodeRequire('csso');
Expand Down Expand Up @@ -96,7 +96,7 @@ define(['require', './normalize'], function(req, normalize) {
// NB add @media query support for media imports
var importRegEx = /@import\s*(url)?\s*(('([^']*)'|"([^"]*)")|\(('([^']*)'|"([^"]*)"|([^\)]*))\))\s*;?/g;
var absUrlRegEx = /^([^\:\/]+:\/)?\//;

// Write Css module definition
var writeCSSDefinition = "define('@writecss', function() {return function writeCss(c) {var d=document,a='appendChild',i='styleSheet',s=d.createElement('style');s.type='text/css';d.getElementsByTagName('head')[0][a](s);s[i]?s[i].cssText=c:s[a](d.createTextNode(c));};});";

Expand All @@ -123,11 +123,12 @@ define(['require', './normalize'], function(req, normalize) {
siteRoot = siteRoot.replace(/\\/g, '/');
}

var fileUrl = req.toUrl(name + '.css');

//external URLS don't get added (just like JS requires)
if (name.match(absUrlRegEx))
if (fileUrl.match(absUrlRegEx))
return load();

var fileUrl = req.toUrl(name + '.css');
if (isWindows)
fileUrl = fileUrl.replace(/\\/g, '/');

Expand Down Expand Up @@ -157,13 +158,13 @@ define(['require', './normalize'], function(req, normalize) {

cssAPI.write = function(pluginName, moduleName, write, parse) {
var cssModule;

//external URLS don't get added (just like JS requires)
if (moduleName.match(absUrlRegEx))
if (!cssBuffer.hasOwnProperty(moduleName))
return;

layerBuffer.push(cssBuffer[moduleName]);

if (!global._requirejsCssData) {
global._requirejsCssData = {
usedBy: {css: true},
Expand Down Expand Up @@ -210,7 +211,7 @@ define(['require', './normalize'], function(req, normalize) {
delete global._requirejsCssData;
}
}

saveFile(outPath, compress(css));
});

Expand Down

0 comments on commit 11d0459

Please sign in to comment.