Search code examples
javascriptnode.jsexpressbundlerparceljs

How to change `sourceMappingURL` in parcel js


How to manually set the path of //# sourceMappingURL inside the created bundle.js? Parcel currently creates a wrong path to the bundle.js.map.

Parcel config:

"scripts": {    
  "watch:js": "parcel watch ./src/js/index.js --out-dir ./public/js --out-file bundle.js",
}

Current Behavior:

 ~ bundle.js ~    

//# sourceMappingURL=/bundle.js.map

Expected Behavior:

~ bundle.js ~    

//# sourceMappingURL=/js/bundle.js.map

Solution

  • One simple workaround is to add the following flag to your call to parcel, which will make the source-map URL relative to the JS file it maps, rather than an absolute.

    --public-url ./
    

    See this GitHub issue for more information.