Joffrey
07/29/2019, 10:10 PMbrowserRun
from the new Kotlin/JS gradle plugin?
Where am I supposed to place my index.html
and other static public files?
I'm seeing a blank page with the text "Cannot GET /" at the top left-hand corner.Soren Valle
07/29/2019, 10:12 PMSoren Valle
07/29/2019, 10:12 PMSoren Valle
07/29/2019, 10:13 PMSoren Valle
07/29/2019, 10:13 PMJoffrey
07/29/2019, 10:14 PMSoren Valle
07/29/2019, 10:14 PMJoffrey
07/29/2019, 10:15 PMSoren Valle
07/29/2019, 10:16 PMSoren Valle
07/29/2019, 10:18 PMJoffrey
07/29/2019, 10:18 PMJoffrey
07/29/2019, 10:19 PMIlya Goncharov [JB]
07/29/2019, 11:32 PMmain
function, and your index.html
is simple and only execute app.js
, you can use generated HTML page, follow host/webpack-dev-server
But in case with necessary custom index.html
you can create it in any place (e.g. $projectDir/static
), and then you need to set this folder as a contentBase
in your DevServer like in @Soren Valle gist. Copying seems redundant.Soren Valle
07/30/2019, 6:47 PM$projectDir/build/processedResources/Js/main
which does not get generated in the tree, only test/ does. The webpack entry is the same as compileKotlinTask.outputFile.parent
, but the output is $projectDir/build/libs
which also does not get generated, it only has some jars in it. So it seems I'm not privy to some auto-magic behavior I have not yet located. Do you have any advice?Ilya Goncharov [JB]
07/30/2019, 7:33 PM%host%/webpack-dev-server
This page show you information about your generating js bundles, including address to generating bundle (e.g. %host%/app.js
). In index.html
you can link on this address (<script src="/app.js">
). Then you should configure DevServer
in runTask
via
devServer = KotlinWebpackConfigWriter.DevServer(contentBase = listOf("%path-to-folder-contains-index.html%"))
Soren Valle
07/30/2019, 11:35 PMindex.html
file in $projectDir/src/main/resources
it copies the files to $projectDir/build/processedResources/Js/main
which is also the default content base of the devServer. From there you can link as needed. I think the WebpackHtmlPlugin might work as well, but I haven't messed with that yet on dev runs. Now to figure out how to get the npm dependencies from including the dev dependencies... Even running dce and Uglify the main bundle was 5mb.Soren Valle
07/30/2019, 11:36 PMsnrostov
08/04/2019, 8:46 AMWhere am I supposed to place my index.html and other static public files?@Joffrey You can put it in the resource root:
src/main/resources
. index.html
should be something like this:
<!DOCTYPE html>
<html lang="en">
<body>
<div id="react-app">Loading...</div>
<script src="project-name.js"></script>
</body>
</html>
Starting from 1.3.50 wizard will create this file by default. You can try eap: https://discuss.kotlinlang.org/t/kotlin-1-3-50-early-access-preview/13525
Currently only build.gradle supported through. See https://youtrack.jetbrains.com/issue/KT-31953 for more details.
There is plan to generate this file automatically behind the scene: https://youtrack.jetbrains.com/issue/KT-31690snrostov
08/04/2019, 8:48 AMyou need to drop the config files in /src/package.json.d/anyname.js and src/webpack.config.d/anyname.js@Soren Valle
/src/package.json.d
is not supported yet, only src/webpack.config.d
Joffrey
08/04/2019, 12:26 PMsrc/main/resources
were copied and served properly (thanks to @Soren Valle's example). Since I didn't want to hardcode the JS filename in index.html
, I configured processResources
to inject the JS file name in it. It might be useful to have this feature out of the box :)snrostov
08/04/2019, 12:28 PMI configuredTotally agreed. It is in the plan: https://youtrack.jetbrains.com/issue/KT-31690to inject the JS file name in it. It might be useful to have this feature out of the box :)processResources
Joffrey
08/04/2019, 12:31 PM