我有一个相当简单的gradle配置,将我的react应用打包到一个Jar中:
plugins {
id 'java'
id 'groovy'
id 'com.moowork.node' version '1.3.1'
}
//...
node {
version = '12.3.1'
npmVersion = '6.9.1-next.0'
download = true
workDir = file "$project.buildDir/nodejs"
npmWorkDir = file "$project.buildDir/npm"
}
task appNpmInstall( type:NpmTask ) {
group = 'node'
description = 'Installs all dependencies from package.json'
workingDir = file "$project.projectDir/src/main/webapp"
args = [ 'install' ]
}
task appNpmBuild( type:NpmTask ) {
dependsOn appNpmInstall
group = 'node'
description = 'Builds production version of the webapp'
workingDir = file "$project.projectDir/src/main/webapp"
args = [ 'run', 'build' ]
}
task copyWebApp( type:Copy ) {
dependsOn appNpmBuild
group = 'node'
description = 'Copies the react webapp into build dir'
from 'src/main/webapp/build'
into "$buildDir/resources/main/webroot"
}
jar.dependsOn copyWebApp
它就像一种魅力。
唯一的问题是npm build
任务可以运行(最多需要15秒!),即使没有更改任何React文件。有什么方法可以使npm构建仅在更改后增量运行?