hey guys, have anyone checked that the `kotlin-dce...
# javascript
d
hey guys, have anyone checked that the
kotlin-dce-js
is generating invalid code?
k
Do you experience any issues with DCE? Can you provide a self-contained example?
d
Yes, Alexey! Sorry about the later response. I was rewriting my react bindings that you can find at
<https://github.com/danfma/kodando-reakt>
and use to reproduce it. Configuration of the environment: 1. Clone the repo; 1.
./gradlew clean build
(to build the project); 2.
yarn install
or
npm install
(to install the dependencies); 3. `yarn start`; Scenario 1 (bundling in development mode - WORKS) 1.
yarn start
(it will use webpack to bundle the project by using the generated files and dependencies without the dce, and it will start a server at the port 3000). Scenario 2 (bundling in production mode - FAIL AT RUNTIME) 1.
yarn build
(it will use the webpack to bundle the project and it will copy the generated files to the path
samples/counter-application/www/js
.
if you check the generated files at the
min
directory, you will see that the generated code ignores the projects in the repository, and create them as almost empty files. So, at runtime, we will get an access to an undefined object (package).
k
@danfma a strange thing happens. I try to disable uglifyjs plugin, and nothing helps. I remove
plugins
section completely and still get minified output. Any suggestions what's wrong?
@danfma I found it! That's because of
Copy code
compileTestKotlin2Js {
        kotlinOptions.metaInfo = true
        kotlinOptions.outputFile = "$project.buildDir.path/js/${project.name}-test.js"
        kotlinOptions.sourceMap = true
        kotlinOptions.sourceMapEmbedSources = "always"
        kotlinOptions.moduleKind = 'commonjs'
    }
So, single output dir used for both main and tests source sets. That caused DCE to overwrite
min
directory when running
:samples:counter-application:runDceTestKotlinJs
. It can be fixed by changing output directory for tests, i.e "$project.buildDir.path/js-test/${project.name}-test.js"
d
Ohhh I will try it. One thing that I realized is that when I defined the project entirely in the project build file (and not with some configurations in a parent build file like in this project) it works. Thanks man!
Yeah, man! You were right! Thanks!