Hi everyone, I was wondering if there is a way to ...
# javascript
f
Hi everyone, I was wondering if there is a way to create different build variants in Gradle for a Kotlin/JS project? I come from an Android background so I'm looking for something similar to "product flavors" where I can have a different configuration for a development and a production build (e.g., using different API base URLs). I know that we can use development and production runs with
browserDevelopmentRun
and
browserProductionRun
but that feels like a "debug" and "release" thing where the former doesn't do any optimisations and the latter does.
t
something similar to “product flavors”
Like this?
f
Thanks for the response @turansky. I'm not sure if that is what I need as the README doesn't have a lot of context. I see that this would allow me to create multiple outputs for different modules but what I actually want is to be able to configure different builds, I don't care about building them at the same time. Maybe I'm not understanding the plugin properly.
1
t
Which options you need to configure?
a
cc @Ilya Goncharov [JB]
i
Hi! We have no exact flavors We have kinds of tasks:
run
and
build
, and you can configure each convenient, but at least for now this configurations affect both production and development variants What options do you want to switch?
f
Hi guys, sorry I think my initial question was not clear, what I want is to have different configuration for development and production environments to point to a development server and production server with different builds. For example: • The development build makes calls to
<https://dev.api.whatever>
and the production build calls
<https://api.whatever>
. Each configuration has a
BASE_URL
constant which value is different depending on the build, so I just use
BASE_URL
in the code and it knows which server to call depending on the build I'm running. • Both the development and production builds can run in
debug
and
release
mode (without and with optimisations respectively).
t
For dynamic webpack configuration you can use webpack plugin
Copy code
./gradlew run -Pmymode=localRelease
Copy code
tasks {
    patchWebpackConfig {
        val mymode = project.property("mymode")   
        // language=JavaScript
        patch("""
            config.mode = ${getMode(mymode)}
            
            // proxy configyration
            config.proxy.url = ${getBaseUrl(mymode)}    
        """)
    }
}
f
Thanks @turansky, will try that 👍