Hi all, I’m having an issue with setting environme...
# javascript
c
Hi all, I’m having an issue with setting environment variables in
build.gradle.kts
to pass as arguments to
webpack-cli
. This is working fine in webpack 4, but I’m trying to upgrade to webpack 5. The following works for webpack 4:
Copy code
kotlin {
    js {
        browser {
            commonWebpackConfig {
                cssSupport.enabled = true
                mode = buildMode
                // stop default export of config object in Webpack code because we do it in 02.envConfig.js webpack extension
                export = false
            }

            // from <https://discuss.kotlinlang.org/t/kotlin-js-react-accessing-configuring-environment-variables/16906/9>
            val envTargetWebpackArgs = listOf("--env.envTarget=$envTarget", "--env.version=$version")
            webpackTask { args.plusAssign(envTargetWebpackArgs) }
            runTask { args.plusAssign(envTargetWebpackArgs) }
        }

        // Necessary to fix a compilation issue (see <https://github.com/Kotlin/dukat/issues/106>)
        useCommonJs()
    }

    // Force explicit APIs
    explicitApi()
}
With the key lines being: