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

Relative path showing up in asset map? #29

Open
rebolyte opened this issue Apr 11, 2017 · 3 comments
Open

Relative path showing up in asset map? #29

rebolyte opened this issue Apr 11, 2017 · 3 comments

Comments

@rebolyte
Copy link

First off, this lib is exactly what I was looking for. Thanks for making it!

I am having an issue with a relative path showing up in the assets JSON file. Basically, I need the entry in the asset map to have a slightly different path from where the file gets output. I need the path to be stored as "js/bundle.{hash}.js" but the file output to "static/js/bundle.{hash}.js". This seems to be exactly what the --cwd option does, and it almost works, but then it creates an entry in the asset map like so:

{
  "../bundle.js": "js/bundle.b1e144c7.js"
}

I don't want the leading ../ on the filename. Where is it coming from? I could go through and strip it off after every build, but that seems hacky.

Here's the NPM script that I'm using:

"prod:js": "rollup --config | uglifyjs --compress --mangle --screw-ie8 | hashmark --cwd static --name bundle.js --silent --length 8 --asset-map ../data/assets.json \"js/{name}.{hash}{ext}\"",

Ideas? Let me know if you need any other info.

@keithamus
Copy link
Owner

@ArnaudRinquin and @gregersrygg both worked on the --cwd flag, maybe they could help here? Is this broken? Do we need to fix this case?

@gregersrygg
Copy link

A long time since I worked on this, so I don't remember much. @rebolyte Have you tried outputting the asset-map to the same folder as the bundles to see if that has any effect? In my head, the path to the asset-map should be relative to the cwd folder, and the paths inside the asset-map should be relative to the asset-maps file path.

@edull24
Copy link

edull24 commented Jul 9, 2020

Thanks to all contributors to this project, it has been very helpful on my journey to replace gulp with npm scripts, which originated from this blog post: https://www.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/.

I too was having issues with the pathing in the asset map file and could never get it to do exactly what I needed. Turns out, I could get exactly what I wanted without even using this package.

Basically, my needs were as follows:

  1. hash the contents of piped input
  2. save the contents to a file, using the hash in the file name
  3. create a json file with no pathing whatsoever, just a key with an original file name and a value of the new "hashed" file name, so something like this:

{"main.css": "main-3a7df308834f8f92d9bf3d0b6d63bfcc.css"}

I was able to accomplish this using the following in my npm scripts:

"css:hash": "(read css; md5sum | (read hash; hash=${hash:0:32}; echo $css > ./dist/css/main-$hash.css; echo '{\"main.css\": \"main-'$hash'.css\"}' > ./dist/css/rev-manifest.json))"

Hopefully this helps someone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants