UNPKG

511 BJavaScriptView Raw
1// @flow strict-local
2
3import URL from 'url';
4import path from 'path';
5
6/**
7 * Joins a path onto a URL, and normalizes Windows paths
8 * e.g. from \path\to\res.js to /path/to/res.js.
9 */
10export default function urlJoin(publicURL: string, assetPath: string): string {
11 const url = URL.parse(publicURL, false, true);
12 const assetUrl = URL.parse(assetPath);
13 url.pathname = path.posix.join(url.pathname, assetUrl.pathname);
14 url.search = assetUrl.search;
15 url.hash = assetUrl.hash;
16 return URL.format(url);
17}