Gradle:仅在代码更改时运行npm构建任务

时间:2019-07-24 08:47:49

标签: node.js gradle npm

我有一个相当简单的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构建仅在更改后增量运行?

0 个答案:

没有答案