-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
61 lines (45 loc) · 1.6 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import com.github.gradle.node.npm.task.NpxTask
plugins {
id("war")
id("com.github.node-gradle.node") version "7.1.0"
}
node {
version = "20.18.0"
download = true
workDir = project.layout.buildDirectory.get().dir("nodejs") // where node is downloaded to
nodeProjectDir = project.rootDir; // where package.json is read and node_modules downloaded
}
tasks.npmInstall {
inputs.file(project.rootDir.resolve("package.json"));
val packageLockFile = project.rootDir.resolve("package-lock.json");
if (packageLockFile.exists()) {
inputs.file(packageLockFile)
}
outputs.file(packageLockFile)
outputs.dir(project.rootDir.resolve("node_modules"))
}
val webpackTask = tasks.register<NpxTask>("webpack") {
dependsOn("npmInstall")
command = "webpack"
workingDir = project.rootDir;
val outputDir = project.layout.buildDirectory.dir("react-js")
val relativeOutputDir = "." + File.separatorChar + outputDir.get().asFile.relativeTo(project.projectDir)
args = listOf(
"--env=entryFile=./src/main/react-js/index.jsx",
"--env=outputDir=$relativeOutputDir",
"--env=outputFilename=index.js"
)
inputs.file(project.rootDir.resolve("webpack.config.js"))
inputs.files(fileTree(rootProject.rootDir.resolve("node_modules")).exclude(".cache"))
inputs.dir(project.projectDir.resolve("src/main/react-js"))
outputs.dir(outputDir)
}
project.afterEvaluate {
tasks.getByName("build").dependsOn(webpackTask);
}
tasks.war {
dependsOn("webpack")
from(project.layout.buildDirectory.dir("react-js")) {
into("js")
}
}