This page contains a collection of frequently asked questions.
Just add to your bundle task filesets (in and out) which this task depends on:
task bundle(type: YarnTask) {
inputs.files(fileTree('node_modules'))
inputs.files(fileTree('src'))
inputs.file('package.json')
inputs.file('webpack.config.js')
outputs.dir('build/resources/static')
dependsOn yarn_install
args = ['run', 'build']
}
More info in Gradle doc
node {
npmInstallCommand = System.getenv("CI") ? 'ci' : 'install'
}
This can be done adding some arguments to the already defined npmInstall
-task. To set the log level to silly
do this:
npmInstall.args = ['--loglevel', 'silly']
This can be done by adding to the arguments for the already defined npmSetup
task.
tasks.npmSetup {
doFirst {
args = args + ['--registry', 'http://myregistry.npm.com']
}
}
You can also add any other arguments to this list that work with npm install
i.e. more verbose modes.
NodeTask
, NpmTask
, NpxTask
and YarnTask
are some wrappers around the core Exec
task.
They have several parameters that enable to customize the way the corresponding command is launched.
The ignoreExitValue
property enables to avoid the task failing if the process exit value is not 0
:
task myScript(type: NodeTask) {
script = file('src/scripts/my.js')
ignoreExitValue = true
}
The workingDirectory
option enables to change the working directory of the process. Note that some commands such as npm
force the working directory to be the one in which the package.json
file is located.
This option is most of the time useless.
task myScript(type: NodeTask) {
script = file('src/file.js')
workingDir = file('./customWorkingDirectory')
}
The environment
option enables to define some new environment variables or override some existing ones:
task command(type: NpxTask) {
command = 'aCommand'
environment = ['CUSTOM_VARIABLE': 'Hello world']
}
The execOverride
option enables to customize all the other thinks that can be configured in an ExecSpec
thanks to
a closure that takes the ExecSpec
as parameter. Note that it is executed last, possibly overriding already set
parameters such as the working directory.
task myScript(type: NpmTask) {
npmCommand = ['run', 'hello']
execOverrides {
// The it variable contains the `ExecSpec`
it.ignoreExitValue = true
it.workingDir = file('./myWorkingDirectory')
it.standardOutput = new FileOutputStream('logs/my.log')
}
}
How do I ignore some files of the node_modules
directory that are modified by the build and prevent tasks from being up-to-date ?
NpmInstallTask
and YarnInstallTask
have an option that enables to exclude some files from the task's output.
Its type is a closure that contains a FileTree
whose root directory is node_modules
.
With npm:
npmInstall {
nodeModulesOutputFilter = { it.exclude("package/package.json") }
}
Note that it
is the implicit closure variable containing the FileTree
instance. It could also be written this way:
nodeModulesOutputFilter = { fileTree -> fileTree.exclude("package/package.json") }
With yarn:
yarn {
nodeModulesOutputFilter = { it.exclude("package/**").exclude("anotherPackage") }
}
Note: the Gradle's up-to-date checking is much slower when using this option. See issue #63.