https://kotlinlang.org logo
b

Brandon Saunders

03/04/2020, 7:22 PM
is there a way to get jsBrowserProductionWebpack working with commonJS as the librarytarget? Our project originally used nodejs as one of our targets but switched to js to get the DCE benefit but the output now isn't immediately consummable. And it doesn't appear like our default webpack config is being used to determine the output
ahh i think i may have found the issue. We had previously been calling webpack on our own. The task seems to assume the existence of a webpack.config.d folder. I'll try that
hmm... no that didn't see to fix it. I'm still not getting a commonjs library despite the webpack.config.js file in my webpack.config.d folder saying to make it so
we're pretty sure the file is being used, because syntax errors in it cause the jsBrowserProductionWebpack task to fail
i

Ilya Goncharov [JB]

03/04/2020, 9:19 PM
Since 1.3.70 standard libraryTarget of webpack is umd, which is compatible with commonjs But if you prefer exactly commonjs you can change it via
Copy code
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackOutput.Target
...
kotlin {
   js {
      webpackTask {
         output.libraryTarget = Target.COMMONJS
      }
   }
}
Via
<http://webpack.co|webpack.co>nfig.d
you can do more fine grained configauration of webpack, but it can be less reliable, and build can be broken Scripts in
<http://webpack.co|webpack.co>nfig.d
simply appends to
<http://webpack.co|webpack.co>nfig.js
and so you can configure webpack through variable
config
j

Janelle Fullen

03/04/2020, 9:36 PM
What do you mean by using the config variable? Normally a webpack config has a module.exports value that properties are set on to determine the configuration.
i

Ilya Goncharov [JB]

03/04/2020, 9:40 PM
Yes, inside out gradle plugin we configure webpack configuration with mode exports, and there is extension point to extense webpack configuration. It is to create javascript file in webpack.config.d and inside this script you can change webpack configuration through
config
variable
So you don’t beed to define fully webpack configuration, you can only a little bit extend it
For example create
<http://webpack.co|webpack.co>nfig.d/something.js
with conent
Copy code
config.output = config.output || {}
config.output.libraryExport = [“com”, “example”]
j

Janelle Fullen

03/04/2020, 10:40 PM
got it, thanks
e

Eivind Nilsbakken

03/06/2020, 7:19 AM
@Ilya Goncharov [JB] Does
webpack.config.d
have to be placed directly under
$projectDir
? I can get it to work that way, but I'd prefer to place it in
src/jsMain/resources
.
Or maybe not, since then I guess it would be copied into the build. So probably fine to have it at the project root then. 🤔
14 Views