Skip to content

Commit

Permalink
Correctly build URLs for CSS
Browse files Browse the repository at this point in the history
Fix real core issue of #2518
  • Loading branch information
mischnic committed Mar 7, 2019
1 parent 95dfb33 commit b1165bf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 1 addition & 5 deletions packages/core/integration-tests/test/css.js
Expand Up @@ -282,11 +282,7 @@ describe('css', function() {

assert(
await fs.exists(
path.join(
__dirname,
path.dirname('/dist/a/style1.css'),
css.match(/url\(([^)]*)\)/)[1]
)
path.join(__dirname, 'dist', css.match(/url\(([^)]*)\)/)[1])
),
'path specified in url() exists'
);
Expand Down
3 changes: 1 addition & 2 deletions packages/core/parcel-bundler/src/Asset.js
Expand Up @@ -257,8 +257,7 @@ class Asset {
// Replace temporary bundle names in the output with the final content-hashed names.
let newValue = value;
for (let [name, map] of bundleNameMap) {
let mapRelative = path.relative(path.dirname(this.relativeName), map);
newValue = newValue.split(name).join(mapRelative);
newValue = newValue.split(name).join(map);
}

// Copy `this.generated` on write so we don't end up writing the final names to the cache.
Expand Down
5 changes: 5 additions & 0 deletions packages/core/parcel-bundler/src/assets/CSSAsset.js
Expand Up @@ -6,6 +6,8 @@ const CssSyntaxError = require('postcss/lib/css-syntax-error');
const SourceMap = require('../SourceMap');
const loadSourceMap = require('../utils/loadSourceMap');
const path = require('path');
const urlJoin = require('../utils/urlJoin');
const isURL = require('../utils/is-url');

const URL_RE = /url\s*\("?(?![a-z]+:)/;
const IMPORT_RE = /@import/;
Expand Down Expand Up @@ -91,6 +93,9 @@ class CSSAsset extends Asset {
let url = this.addURLDependency(node.nodes[0].value, {
loc: decl.source.start
});
if (!isURL(url)) {
url = urlJoin(this.options.publicURL, url);
}
dirty = node.nodes[0].value !== url;
node.nodes[0].value = url;
}
Expand Down

0 comments on commit b1165bf

Please sign in to comment.