Running npm install with sbt

2.2k Views Asked by At

So I have a sbt project that uses sbt-js-engine and sbt-webpack plugins.

It successfully gets and resolves npm packages just fine. And then webpack would build the project.

I have added a npm install script into package.json like so,

  "scripts": {
    "install": "bower install"
  }

However, the problem I am currently having is that when I run webpack (which intern uses sbt-js-engine ) it runs npm update instead of npm install.

Heres an excerpt of my build.sbt,

lazy val common = project.in(file("common")).
  enablePlugins(SbtWeb).
  settings(
    sourceDirectory in webpack := baseDirectory.value,
    resourceManaged in webpack := (resourceManaged in webpack in root).value,
    includeFilter in webpack := ("*.jsx" || "*.js" || "*.json") && new FileFilter {
      @tailrec
      override def accept(pathname: File): Boolean = {
        if (pathname == null) false
        else if (pathname.getName == "javascripts") true
        else accept(pathname.getParentFile)
      }
    },
    JsEngineKeys.engineType := JsEngineKeys.EngineType.Node
  )

Is there anyway I could run npm install instead or even before as a depedency for webpack task ?

1

There are 1 best solutions below

0
On BEST ANSWER

You could try something like this:

sourceDirectory in webpack := {
    Process("/usr/local/bin/npm install", file("[path to working dir]")).!
    baseDirectory.value
}

That would mean it would run at same time as setting the webpack settings.