@@ -12,19 +12,19 @@ It is also able to install [Yarn](https://yarnpkg.com/) by downloading it from a
12
12
13
13
The version of each tool to use can be specified in the configuration.
14
14
15
- To start using the plugin, add this into your ` build.gradle `
15
+ To start using the plugin, add this into your ` build.gradle `
16
16
file (see [ Installing] ( installation.md ) for details):
17
17
18
18
19
19
``` gradle
20
20
plugins {
21
- id "com.github.node-gradle.node" version "4 .0.0"
21
+ id "com.github.node-gradle.node" version "5 .0.0"
22
22
}
23
23
```
24
24
25
25
## Running a Node.js Script
26
26
27
- To use this plugin you have to define some tasks in your ` build.gradle ` file. If you have a Node.js
27
+ To use this plugin you have to define some tasks in your ` build.gradle ` file. If you have a Node.js
28
28
script in ` src/scripts/my.js ` , then you can execute this by defining the following Gradle task:
29
29
30
30
``` gradle
@@ -51,14 +51,14 @@ task myScript(type: NodeTask) {
51
51
}
52
52
```
53
53
54
- When executing this task for the first time, it will run a ` nodeSetup ` task that downloads Node.js
55
- (for your platform) and NPM (Node Package Manager) if on Windows (other platforms include
54
+ When executing this task for the first time, it will run a ` nodeSetup ` task that downloads Node.js
55
+ (for your platform) and NPM (Node Package Manager) if on Windows (other platforms include
56
56
it into the distribution).
57
57
58
58
## Executing ` npm ` Tasks
59
59
60
- When adding the node plugin, you will have a ` npmInstall ` task already added. This task will
61
- execute ` npm install ` and installs all dependencies in ` package.json ` . It will only run when changes
60
+ When adding the node plugin, you will have a ` npmInstall ` task already added. This task will
61
+ execute ` npm install ` and installs all dependencies in ` package.json ` . It will only run when changes
62
62
are made to ` package.json ` , ` npm-shrinkwrap.json ` , ` package-lock.json ` or ` node_modules ` . Execute it like this:
63
63
64
64
``` bash
@@ -77,7 +77,7 @@ $ gradle npm_cache_clean
77
77
...
78
78
```
79
79
80
- These however are not shown when running gradle tasks, as they generated dynamically. However they can
80
+ These however are not shown when running gradle tasks, as they generated dynamically. However they can
81
81
be used for dependency declarations, such as:
82
82
83
83
``` gradle
@@ -104,19 +104,19 @@ task installExpress(type: NpmTask) {
104
104
## Executing ` npm ` Commands via ` npx `
105
105
106
106
[ As of 5.2] ( https://blog.npmjs.org/post/162869356040/introducing-npx-an-npm-package-runner ) ,
107
- ` npm ` is bundled with a new command called [ ` npx ` ] ( https://www.npmjs.com/package/npx ) which is aimed at running CLI
108
- commands from NPM packages.
107
+ ` npm ` is bundled with a new command called [ ` npx ` ] ( https://www.npmjs.com/package/npx ) which is aimed at running CLI
108
+ commands from NPM packages.
109
109
110
- It enables to execute ` npm ` commands without needing to declare them as a ` script ` in the ` package.json ` file and run
110
+ It enables to execute ` npm ` commands without needing to declare them as a ` script ` in the ` package.json ` file and run
111
111
thanks to the ` npm run ` command.
112
112
113
- It does not require the command to be locally or globally installed. If the command is not already installed, the
113
+ It does not require the command to be locally or globally installed. If the command is not already installed, the
114
114
corresponding package is installed then the command is run. In this case, it is necessary to indicate the package
115
115
name instead of the command name.
116
-
117
- The ` NpxTask ` is able to execute some ` npx ` commands. It depends on the ` npmSetup ` to ensure ` npx ` is available.
118
116
119
- To generate a new Angular project with the ` ng ` command coming from ` @angular/cli ` which is not installed
117
+ The ` NpxTask ` is able to execute some ` npx ` commands. It depends on the ` npmSetup ` to ensure ` npx ` is available.
118
+
119
+ To generate a new Angular project with the ` ng ` command coming from ` @angular/cli ` which is not installed
120
120
(note that we can specify the version):
121
121
122
122
``` gradle
@@ -142,8 +142,8 @@ task buildAngularApp(type: NpxTask) {
142
142
143
143
## Executing Yarn Tasks
144
144
145
- When adding the node plugin, you will have a yarn task already added. This task will
146
- execute ` yarn ` and installs all dependencies in ` package.json ` . It will only run when changes
145
+ When adding the node plugin, you will have a yarn task already added. This task will
146
+ execute ` yarn ` and installs all dependencies in ` package.json ` . It will only run when changes
147
147
are made to ` package.json ` , ` yarn.lock ` , or ` node_modules ` . Execute it like this:
148
148
149
149
``` bash
@@ -160,7 +160,7 @@ $ gradle yarn_cache_clean
160
160
...
161
161
```
162
162
163
- These however are not shown when running gradle tasks, as they generated dynamically. However they can be
163
+ These however are not shown when running gradle tasks, as they generated dynamically. However they can be
164
164
used for dependency declarations, such as:
165
165
166
166
``` gradle
@@ -191,7 +191,7 @@ You can configure the plugin through the `node` extension.
191
191
Here is the list of all available configuration properties using the Groovy DSL.
192
192
See [ here] ( ../src/test/resources/fixtures/kotlin/build.gradle.kts ) to see a Kotlin DSL example.
193
193
194
- The values shown here are the default ones. We recommend to define only the ones for which the
194
+ The values shown here are the default ones. We recommend to define only the ones for which the
195
195
default value is not satisfying.
196
196
197
197
``` gradle
@@ -201,51 +201,51 @@ node {
201
201
// If true, it will download node using above parameters
202
202
// Note that npm is bundled with Node.js
203
203
download = false
204
-
204
+
205
205
// Version of node to download and install (only used if download is true)
206
206
// It will be unpacked in the workDir
207
207
version = "16.14.0"
208
-
208
+
209
209
// Version of npm to use
210
210
// If specified, installs it in the npmWorkDir
211
211
// If empty, the plugin will use the npm command bundled with Node.js
212
212
npmVersion = ""
213
-
213
+
214
214
// Version of Yarn to use
215
215
// Any Yarn task first installs Yarn in the yarnWorkDir
216
216
// It uses the specified version if defined and the latest version otherwise (by default)
217
217
yarnVersion = ""
218
-
218
+
219
219
// Base URL for fetching node distributions
220
220
// Only used if download is true
221
221
// Change it if you want to use a mirror
222
222
// Or set to null if you want to add the repository on your own.
223
223
distBaseUrl = "https://nodejs.org/dist"
224
-
224
+
225
225
// Specifies whether it is acceptable to communicate with the Node.js repository over an insecure HTTP connection.
226
226
// Only used if download is true
227
227
// Change it to true if you use a mirror that uses HTTP rather than HTTPS
228
228
// Or set to null if you want to use Gradle's default behaviour.
229
229
allowInsecureProtocol = null
230
-
230
+
231
231
// The npm command executed by the npmInstall task
232
232
// By default it is install but it can be changed to ci
233
233
npmInstallCommand = "install"
234
-
235
- // The directory where Node.js is unpacked (when download is true)
234
+
235
+ // The directory where Node.js is unpacked (when download is true)
236
236
workDir = file("${project.projectDir}/.gradle/nodejs")
237
-
237
+
238
238
// The directory where npm is installed (when a specific version is defined)
239
239
npmWorkDir = file("${project.projectDir}/.gradle/npm")
240
-
240
+
241
241
// The directory where yarn is installed (when a Yarn task is used)
242
242
yarnWorkDir = file("${project.projectDir}/.gradle/yarn")
243
-
243
+
244
244
// The Node.js project directory location
245
245
// This is where the package.json file and node_modules directory are located
246
246
// By default it is at the root of the current project
247
247
nodeProjectDir = file("${project.projectDir}")
248
-
248
+
249
249
// Whether the plugin automatically should add the proxy configuration to npm and yarn commands
250
250
// according the proxy configuration defined for Gradle
251
251
// Disable this option if you want to configure the proxy for npm or yarn on your own
0 commit comments