node-gradle / gradle-node-plugin

Gradle plugin for integrating NodeJS in your build. :rocket:
Apache License 2.0
615 stars 119 forks source link

How to use npm scripts? #212

Closed JacquesLeRoux closed 2 years ago

JacquesLeRoux commented 2 years ago

Hi,

I have added "uglify-js": "latest" in package.json and also added

    "scripts": {
        "uglify": "uglifyjs test.js --compress --mangle --output test.min.js"
    }

But I'm unsure how to run the "uglify" "script". Among others, I tried gradlew npm_run and got this result:

> Task :nodeSetup UP-TO-DATE
> Task :npmSetup SKIPPED
> Task :npmInstall UP-TO-DATE
> Task :npm_run
Scripts available [...] via `npm run-script`:
  uglify
    uglifyjs test.js --compress --mangle --output test.min.js

How (syntax) can I run the uglify "script"? I have tried many other ways, did not find the right one :/

Thanks in advance

JacquesLeRoux commented 2 years ago

Forgot to say that npm exec uglifyjs test.js, in dir where uglifyjs is, works

deepy commented 2 years ago

If you want to use the rules-based automatic task creation it'd be npm_run_uglify (since the normal syntax is npm run uglify) but if this is something that's going to be part of your build I recommend creating a NpmTask for it (and possibly registering inputs/outputs and marking it as cacheable)

JacquesLeRoux commented 2 years ago

Thanks, I'll try that