Is there a way to conditionally include NPM depend...
# javascript
a
Is there a way to conditionally include NPM dependancies depending on the type, e.g. Browser or Node. I have a scenarios where i do not wish to include the npm dependancies on my node target, but need them for my browser target.
b
Split them into different sourceSets and put shared code in third sourceSet
a
i tried this but then i get an error about the metadata being identical of two JS targets.
b
Separate modules then?
r
You can use something like this to disambiguate multiple targets of the same type https://kotlinlang.org/docs/mpp-set-up-targets.html#distinguish-several-targets-for-one-platform
It's a bit clunky though. I really wish browser and node were separate targets the way the different native platforms are
a
i actually did that too 🤣 So my first project is a Multiplatform library, so i created two JS targets with a unique attribute. When i publish them locally, when my Application trys to fetch them, it fails
even with the extra attribute in both the ‘Application’ and library
r
oh really? I haven't tried it in a while but I'm pretty sure that's how it's supposed to work
a
Its as if the consuming project(Application) is unable to use the extra attribute when fetching the Library
although in my example above, i didnt use the attributes
But i have done previously
i think the attributes stuff only works for publishing, but when it comes to trying to consume from another multiplatform project, then it fails.
r
I've successfully used (custom) attributes to resolve
project()
dependencies for 2 JVM targets. How did you set the attribute when consuming it? I did it in the dependency configuration block (
implelemtation(project()){ attributes{ ... } }
) which worked
a
hi ryan do you have a sample build gradle with this in?
just to make sure i was putting it in the right place for the consumer
a
wow thanks, i will have to give it another go.
t
create a multiplatform Full stack project. If in Intellij you create a new project as full stack you will see two source sets one is jvmMain and other is jsMain. You can use the same template for your project.
a
@Tarun Chawla - the question is about targeting the same platform target (javascript) but one for Node and one for browser where they have different dependancies.
👍 1
i havent had chance yet to try out Ryans solution, but hopefully should work
@rnett - i tried to replicate what you did in your project, i found i get this error:
Copy code
Cannot resolve project dependency project ':firebase-app' -> project ':firebase-common'.Dependency to project with multiple js compilation not supported yet.
I guess i will have to wait till its officially supported.