diff --git a/index.js b/index.js index 7cd9c54..96488ba 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ var assign = require("object-assign") var features = { // Reminder: order is important import: function(options) { return require("postcss-import")(options) }, + url: function(options) { return require("postcss-url")(options) }, customProperties: function(options) { return require("postcss-custom-properties")(options) }, calc: function(options) { return require("postcss-calc")(options)}, customMedia: function(options) { return require("postcss-custom-media")(options)}, @@ -60,7 +61,7 @@ function cssnext(string, options) { var postcss = Postcss() Object.keys(cssnext.features).forEach(function(key) { - // if undefined, we use consider feature is wanted (default behavior) + // if undefined, we default to assuming this feature is wanted by the user if (features[key] !== false) { postcss.use(cssnext.features[key](typeof features[key] === "object" ? features[key] : undefined)) } diff --git a/package.json b/package.json index 177bdbe..e65fe6b 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "postcss-font-variant": "^1.0.0", "postcss-import": "^5.0.0", "postcss-media-minmax": "^1.1.0", + "postcss-url": "^2.0.0", "read-file-stdin": "^0.2.0", "to-slug-case": "^0.1.2", "to-space-case": "^0.1.3", diff --git a/test/features.js b/test/features.js index 6142676..4d4c5e3 100644 --- a/test/features.js +++ b/test/features.js @@ -21,8 +21,14 @@ var testFeature = function(t, feature, cssnext, version, source, input, expected t.notEqual(css, expected, version + ": should not add " + feature + " support if disabled") t.equal(css, input, version + ": should not modify input if " + feature + " is disabled") - // enable only the one we want to test + // enable only the one we want to test... options.features[feature] = true + + // ...except "url" because we want to validate its behaviour when integrated + // with "import" + if (feature === "url") { + options.features["import"] = true + } t.equal(cssnext(input, options).trim(), expected.trim(), version + ": should add " + feature + " support") } @@ -35,8 +41,8 @@ Object.keys(cssnext.features).forEach(function(name) { test(slug, function(t) { testFeature(t, name, cssnext, "node.js", source, input, expected) - // we do not support @import in the browser - if ("import" === name) { + // we do not support @import or url rewriting in the browser + if ("import" === name || "url" === name) { t.end() return } diff --git a/test/features/url.css b/test/features/url.css new file mode 100644 index 0000000..272d4c4 --- /dev/null +++ b/test/features/url.css @@ -0,0 +1 @@ +@import './url/dependency' diff --git a/test/features/url.expected.css b/test/features/url.expected.css new file mode 100644 index 0000000..2e7c6ad --- /dev/null +++ b/test/features/url.expected.css @@ -0,0 +1,4 @@ +@font-face { + name: 'url-font'; + src: url('url/assets/source-sans-regular.woff') +} diff --git a/test/features/url/assets/source-sans-regular.woff b/test/features/url/assets/source-sans-regular.woff new file mode 100644 index 0000000..34fdfde Binary files /dev/null and b/test/features/url/assets/source-sans-regular.woff differ diff --git a/test/features/url/dependency.css b/test/features/url/dependency.css new file mode 100644 index 0000000..aa0b966 --- /dev/null +++ b/test/features/url/dependency.css @@ -0,0 +1,4 @@ +@font-face { + name: 'url-font'; + src: url('./assets/source-sans-regular.woff'); +}