Edoardo Luppi
07/04/2023, 10:52 AMtasks.withType<Kotlin2JsCompile>().configureEach {
kotlinOptions {
sourceMap = true
sourceMapEmbedSources = "always"
sourceMapNamesPolicy = "fully-qualified-names"
}
}
The generated source map file is as following:
{
"version": 3,
"sources": [
"../../../../../../src/commonMain/kotlin/...",
"../../../../../../src/jsMain/kotlin/...",
...
],
"sourcesContent": [ ... ], // here I can see my source code
"names": [ ... ],
"mappings": "..."
}
In the VS Code side I've configured the launch.json
task file as following:
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}",
"sourceMaps": true,
"pauseForSourceMap": true
}
But yet I can't get source maps to work. I still debug and see the compiled JS.Adam S
07/04/2023, 11:01 AMEdoardo Luppi
07/04/2023, 11:03 AMEdoardo Luppi
07/04/2023, 11:03 AMAdam S
07/04/2023, 11:05 AMkotlin {
js {
binaries.executable()
}
}
add a fun main()
and then run ./gradlew jsBrowserDevelopmentRun
Adam S
07/04/2023, 11:05 AMEdoardo Luppi
07/04/2023, 11:06 AMEdoardo Luppi
07/04/2023, 11:11 AMAdam S
07/04/2023, 11:14 AMjsNodeDevelopmentRun
but I’m not sure how that will work with the source maps…Edoardo Luppi
07/04/2023, 11:17 AMEdoardo Luppi
07/04/2023, 12:25 PMjsBrowserDevelopmentRun
it opens a Chrome window with a list of files, is that expected?Adam S
07/04/2023, 12:26 PMsrc/jsMain/resources/index.html
, then yesEdoardo Luppi
07/04/2023, 12:27 PMAdam S
07/04/2023, 12:28 PMAdam S
07/04/2023, 12:28 PM<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JS Client</title>
</head>
<body>
<script src="js-tutorial.js"></script>
</body>
</html>
Adam S
07/04/2023, 12:28 PMEdoardo Luppi
07/04/2023, 12:29 PMEdoardo Luppi
07/04/2023, 12:30 PMArtem Kobzar
07/04/2023, 1:21 PM.js
files inside the dist directory contain the sourceMap comment at the end?Edoardo Luppi
07/04/2023, 1:22 PM//# sourceMappingURL=zproto.js.map
Artem Kobzar
07/04/2023, 1:29 PM"webRoot": "${workspaceFolder}"
Artem Kobzar
07/04/2023, 1:31 PMEdoardo Luppi
07/04/2023, 1:31 PMArtem Kobzar
07/04/2023, 1:31 PMresolveSourceMapLocations
?Edoardo Luppi
07/04/2023, 1:31 PM"resolveSourceMapLocations": []
So that every location is used to resolve source mapsEdoardo Luppi
07/04/2023, 1:32 PMsources
pointing at non-existing files?
Being that I'm using the library in another project those relative URLs point to files that do not existArtem Kobzar
07/04/2023, 1:35 PMsourceMapPathOverrides
:
"sourceMapPathOverrides": {
"*": "${workspaceFolder}/dist/*"
}
Edoardo Luppi
07/04/2023, 1:35 PMArtem Kobzar
07/04/2023, 1:37 PMnull
instead of the empty array for `resolveSourceMapLocations`: https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_source-map-resolutionEdoardo Luppi
07/04/2023, 1:43 PM"resolveSourceMapLocations": null,
"sourceMapPathOverrides": {
"../../../../../src/*": "C:/Users/edoardo.luppi/IdeaProjects/zproto/src/*",
"webpack://?:*/*": "${workspaceFolder}/*"
},
Edoardo Luppi
07/04/2023, 1:47 PMEdoardo Luppi
07/04/2023, 2:24 PMArtem Kobzar
07/04/2023, 2:33 PMsourceMapPathOverrides
the regular variant :
"*": "${workspaceFolder}/dist/*"
Artem Kobzar
07/04/2023, 2:34 PM//# sourceMappingURL=zproto.js.map
Without the webpack
prefixEdoardo Luppi
07/04/2023, 2:38 PMsourceMapPathOverrides
referring to the "sources"
field in the .map
file?Edoardo Luppi
07/04/2023, 2:38 PMsourceRoot
with each sources
entry, and then applies the transformationEdoardo Luppi
07/04/2023, 3:42 PMEdoardo Luppi
07/04/2023, 3:46 PMEdoardo Luppi
07/04/2023, 3:51 PM"sourceMaps": true,
"resolveSourceMapLocations": [
"${workspaceFolder}/**",
]
Now I've got to get back to the extension again, but it looks like it's configured in the same way lolEdoardo Luppi
07/04/2023, 3:56 PMEdoardo Luppi
07/04/2023, 3:57 PMEdoardo Luppi
07/05/2023, 8:40 AMyo code
) and you do not use Webpack as bundler, source maps work.Edoardo Luppi
07/05/2023, 9:37 AMextension.js
file, and that's why it messes up the source files.
When you start a VSC extension for debugging, the watch
command is executed.
Webpack bundling: "watch": "webpack --watch",
No Webpack/no bundling: "watch": "tsc -watch -p ./",
Thus Webpack is bundling even when you want to debug. That's why source maps do not work, or they work intermittently.
You can (mostly) workaround the Webpack issue by setting devtool: 'source-map'
in webpack.config.js
, although source maps will not be loaded immediately