From d0e3cf081f61172d143163a4adebea3348307ff6 Mon Sep 17 00:00:00 2001 From: Manuel Mujica Date: Mon, 1 May 2017 16:45:18 -0600 Subject: [PATCH] Prevent clean-css to rebase urls Closes #689 --- lib/assign_default_options.js | 1 + test/css_image_urls/foo.js | 1 + test/css_image_urls/main.css | 1 + test/css_image_urls/main.js | 1 + test/css_image_urls/stealconfig.js | 8 ++++++ test/multibuild_test.js | 40 ++++++++++++++++++++++++------ 6 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 test/css_image_urls/foo.js create mode 100644 test/css_image_urls/main.css create mode 100644 test/css_image_urls/main.js create mode 100644 test/css_image_urls/stealconfig.js diff --git a/lib/assign_default_options.js b/lib/assign_default_options.js index 6b1f5dcc..e2cbccc4 100644 --- a/lib/assign_default_options.js +++ b/lib/assign_default_options.js @@ -12,6 +12,7 @@ module.exports = function(config, options){ bundleSteal: false, uglifyOptions: {}, cleanCSSOptions: { + rebase: false, inline: ["none"] }, removeDevelopmentCode: true, diff --git a/test/css_image_urls/foo.js b/test/css_image_urls/foo.js new file mode 100644 index 00000000..398de92d --- /dev/null +++ b/test/css_image_urls/foo.js @@ -0,0 +1 @@ +require("./main.css"); diff --git a/test/css_image_urls/main.css b/test/css_image_urls/main.css new file mode 100644 index 00000000..e9741621 --- /dev/null +++ b/test/css_image_urls/main.css @@ -0,0 +1 @@ +.topbanner { background-image: url("../../../topbanner.png"); } diff --git a/test/css_image_urls/main.js b/test/css_image_urls/main.js new file mode 100644 index 00000000..398de92d --- /dev/null +++ b/test/css_image_urls/main.js @@ -0,0 +1 @@ +require("./main.css"); diff --git a/test/css_image_urls/stealconfig.js b/test/css_image_urls/stealconfig.js new file mode 100644 index 00000000..d4297edc --- /dev/null +++ b/test/css_image_urls/stealconfig.js @@ -0,0 +1,8 @@ +steal.config({ + ext: { + "css": "steal-css" + }, + paths: { + "steal-css": "../steal-css.js" + } +}); diff --git a/test/multibuild_test.js b/test/multibuild_test.js index b4ead37d..c1f93e9f 100644 --- a/test/multibuild_test.js +++ b/test/multibuild_test.js @@ -1,11 +1,12 @@ -var asap = require("pdenodeify"), - assert = require("assert"), - comparify = require("comparify"), - fs = require("fs-extra"), - multiBuild = require("../lib/build/multi"), - rmdir = require("rimraf"), - path = require("path"), - testHelpers = require("./helpers"); +var asap = require("pdenodeify"); +var assert = require("assert"); +var comparify = require("comparify"); +var fs = require("fs-extra"); +var multiBuild = require("../lib/build/multi"); +var rmdir = require("rimraf"); +var path = require("path"); +var testHelpers = require("./helpers"); +var _escapeRegExp = require("lodash/escapeRegExp"); var find = testHelpers.find; var open = testHelpers.open; @@ -2139,4 +2140,27 @@ describe("multi build", function(){ done(); }); }); + + it("clean-css should not rebase urls by default", function() { + var base = path.join(__dirname, "css_image_urls"); + + return asap(rmdir)(path.join(base, "dist")) + .then(function() { + return multiBuild({ + main: "main", + config: path.join(base, "stealconfig.js") + }, { + quiet: true + }); + }) + .then(function() { + return asap(fs.readFile)( + path.join(base, "dist", "bundles", "main.css") + ); + }) + .then(function(source) { + var rx = new RegExp(_escapeRegExp("url(../../../../../topbanner.png)")); + assert.ok(rx.test(source), "image url should be relative to 'dist'"); + }); + }); });