Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize path for windows os #197

Merged
merged 2 commits into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/assets/HTMLAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/packagers/HTMLPackager.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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)),
''
)
}
});
}
Expand Down
7 changes: 4 additions & 3 deletions src/packagers/RawPackager.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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()),
''
);
}

Expand Down