Closed brainopener closed 6 years ago
I think you have 2-3 options.
One is to use Nashorn's load
function that takes an object with script
and name
, see https://wiki.openjdk.java.net/display/Nashorn/Nashorn+extensions.
Another is to do scriptEngine.put(ScriptEngine.FILENAME, scriptPath)
before evaluating code. I'm not sure about this one, I have had varying success with it.
A third is to embed an inline source map. A bit far-fetched perhaps... :)
So I ended adding this to the top of my JavaScript files:
//# sourceURL=mlspriority.js
Is that what you meant by source map?
No, I was thinking:
//@ sourceMappingURL=data:application/json;charset=utf-8;base64,...
But it was just a guess. Does sourceURL
work well?
It works pretty well.
Here's what it looks like:
In that view mlspriority.js
is the named script using the technique above. Script
and Script1
are different scripts that do not use the technique.
In this project, we compile the scripts. If we notice that the JS file has changed on disk, we reload the script and recompile it. Here's what that looks like then:
The new script is now mlspriority_ndx1.js
.
I have changed the code that detects script reload due to #98, but it's not merged to master yet (because the issue reporter hasn't tested yet). Feel free to test branch issue-98
for the new reload behavior!
Just tried it...
It does indeed suppress the creation of those _ndx#
scripts in DevTools on script change.
Breakpoints survive across script changes too.
Thanks!
Is it possible to name the scripts that show up in the Chrome Debugger?
Currently, I see Script, Script1, Script2, etc...