npmOptionalDirectory

abstract fun npmOptionalDirectory(name: String, directory: Provider<Directory>)

Declares a dependency on a NPM module located in a local directory that is added to optionalDependencies.

NPM optional dependencies should not be applied to Gradle dependency scopes such as api, implementation, and so on. Calling npmOptionalDirectory will automatically add it to the enclosing dependency collector.

directory is resolved lazily, so it may be provided by a value that are not yet known when the declaration is made:

kotlin.sourceSets["jsMain"].dependencies {
npmOptional("is-odd-even", project.layout.buildDirectory.dir("npm/is-odd-even"))
}

If directory has no value, then the build fails when the declaration is used.

The dependency is declared with the NPM local path notation using the absolute path of the directory.

Creating NPM dependencies is only relevant for Kotlin entities that target JS or WasmJS.

Parameters

name

The NPM dependency name

directory

The provider of the directory where dependency files are located