b

    Brandon Saunders

    2 years ago
    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
    Ilya Goncharov [JB]

    Ilya Goncharov [JB]

    2 years ago
    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
    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

    2 years ago
    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.
    Ilya Goncharov [JB]

    Ilya Goncharov [JB]

    2 years ago
    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
    config.output = config.output || {}
    config.output.libraryExport = [“com”, “example”]
    j

    Janelle Fullen

    2 years ago
    got it, thanks
    Eivind Nilsbakken

    Eivind Nilsbakken

    2 years ago
    @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. 🤔