diff --git a/src/assets/HTMLAsset.js b/src/assets/HTMLAsset.js
index 446ba8c0fd7..e3b2b13c296 100644
--- a/src/assets/HTMLAsset.js
+++ b/src/assets/HTMLAsset.js
@@ -3,6 +3,7 @@ const posthtml = require('posthtml');
const parse = require('posthtml-parser');
const api = require('posthtml/lib/api');
const path = require('path');
+const url = require('url');
const md5 = require('../utils/md5');
const render = require('posthtml-render');
const posthtmlTransform = require('../transforms/posthtml');
@@ -47,7 +48,12 @@ class HTMLAsset extends Asset {
if (elements && elements.includes(node.tag)) {
let assetPath = this.addURLDependency(node.attrs[attr]);
if (!isURL(assetPath)) {
- assetPath = path.join(this.options.publicURL, assetPath);
+ // Use url.resolve to normalize path for windows
+ // from \path\to\res.js to /path/to/res.js
+ assetPath = url.resolve(
+ path.join(this.options.publicURL, assetPath),
+ ''
+ );
}
node.attrs[attr] = assetPath;
this.isAstDirty = true;
diff --git a/src/packagers/HTMLPackager.js b/src/packagers/HTMLPackager.js
index a2e8677b176..d0b68b637c5 100644
--- a/src/packagers/HTMLPackager.js
+++ b/src/packagers/HTMLPackager.js
@@ -1,6 +1,7 @@
const Packager = require('./Packager');
const posthtml = require('posthtml');
const path = require('path');
+const url = require('url');
class HTMLPackager extends Packager {
async addAsset(asset) {
@@ -39,7 +40,10 @@ class HTMLPackager extends Packager {
tag: 'link',
attrs: {
rel: 'stylesheet',
- href: path.join(this.options.publicURL, path.basename(bundle.name))
+ href: url.resolve(
+ path.join(this.options.publicURL, path.basename(bundle.name)),
+ ''
+ )
}
});
}
diff --git a/src/packagers/RawPackager.js b/src/packagers/RawPackager.js
index 08ac88c40f6..4cd6d47b5c3 100644
--- a/src/packagers/RawPackager.js
+++ b/src/packagers/RawPackager.js
@@ -1,6 +1,7 @@
const Packager = require('./Packager');
const fs = require('../utils/fs');
const path = require('path');
+const url = require('url');
class RawPackager extends Packager {
// Override so we don't create a file for this bundle.
@@ -11,9 +12,9 @@ class RawPackager extends Packager {
// Use the bundle name if this is the entry asset, otherwise generate one.
let name = this.bundle.name;
if (asset !== this.bundle.entryAsset) {
- name = path.join(
- path.dirname(this.bundle.name),
- asset.generateBundleName()
+ name = url.resolve(
+ path.join(path.dirname(this.bundle.name), asset.generateBundleName()),
+ ''
);
}