Giter Site home page Giter Site logo

Comments (11)

lbialy avatar lbialy commented on August 20, 2024

Sorry, I'm not using Windows :( Shouldn't happen anyway. I'll try to update this seed today and check if it builds on my pals laptop with Win 8.1.

from play-ng2-webpack2.

hatemismail avatar hatemismail commented on August 20, 2024

For my case it was resolved by updating project/UIBuild.scala to detect windows and set run directly from npm bin location:

if(System.getProperty("os.name").toUpperCase().indexOf("WIN") >= 0){
            Process("node \"/Program Files/nodejs/node_modules/npm/bin/npm-cli.js\" install" :: Nil, base / "ui").run
          }

and all file will be:

import java.net.InetSocketAddress
  
  import scala.sys.process.Process
  
  import play.sbt.PlayRunHook
  import sbt._
  
  object UIBuild {
    def apply(base: File): PlayRunHook = {
      object UIBuildHook extends PlayRunHook {
        var process: Option[Process] = None
  
        override def beforeStarted() = {
          if (!(base / "ui" / "node_modules").exists())
            if(System.getProperty("os.name").toUpperCase().indexOf("WIN") >= 0){
              Process("node \"/Program Files/nodejs/node_modules/npm/bin/npm-cli.js\" install" :: Nil, base / "ui").run
            } else {
              Process("npm" :: "install" :: Nil, base / "ui").run
            }
        }
  
        override def afterStarted(addr: InetSocketAddress) = {
          if(System.getProperty("os.name").toUpperCase().indexOf("WIN") >= 0){
            Process("node ./node_modules/webpack/bin/webpack.js --watch", base / "ui/").run
          }else{
            process = Option(
              Process("node_modules/webpack/bin/webpack.js --watch", base / "ui").run
            )
          }
        }
  
        override def afterStopped() = {
          process.foreach(_.destroy())
          process = None
        }
      }
  
      UIBuildHook
    }
  }

from play-ng2-webpack2.

lbialy avatar lbialy commented on August 20, 2024

Sorry for long lack of activity here, got a new job and been pretty busy, but I've been reading a lot on the issues regarding play+ng2+webpack2 lately and I've prepared a plan for updates. Please see: #3. Any ideas, comments and critique are welcome of course.

from play-ng2-webpack2.

lbialy avatar lbialy commented on August 20, 2024

I'll try to incorporate this solution soon.

from play-ng2-webpack2.

JFCote avatar JFCote commented on August 20, 2024

I have the same problem as @hanch04 . The first error was fixed by the code from @hatemismail but even if everything compiles, I have the second problem with the 404... Any idea on how to fix that?

Errors are as follow in the Console:

Failed to load resource: the server responded with a status of 404 (Not Found) : inline.bundle.js (http://localhost:9000/assets/ui/inline.bundle.js)
Failed to load resource: the server responded with a status of 404 (Not Found): polyfills.bundle.js
(http://localhost:9000/assets/ui/polyfills.bundle.js)
Failed to load resource: the server responded with a status of 404 (Not Found): main.bundle.js 
(http://localhost:9000/assets/ui/main.bundle.js)
Failed to load resource: the server responded with a status of 404 (Not Found): vendor.bundle.js 
(http://localhost:9000/assets/ui/vendor.bundle.js)
Failed to load resource: the server responded with a status of 404 (Not Found) ::9000/assets/ui/styles.bundle.css
(http://localhost:9000/assets/ui/styles.bundle.css)
Failed to load resource: the server responded with a status of 404 (Not Found): polyfills.bundle.js 
(http://localhost:9000/assets/ui/polyfills.bundle.js)
Failed to load resource: the server responded with a status of 404 (Not Found): vendor.bundle.js 
(http://localhost:9000/assets/ui/vendor.bundle.js)
Failed to load resource: the server responded with a status of 404 (Not Found): main.bundle.js 
(http://localhost:9000/assets/ui/main.bundle.js)
Failed to load resource: the server responded with a status of 404 (Not Found): styles.bundle.css 
(http://localhost:9000/assets/ui/styles.bundle.css)

When I run npm run start in the ui folder, it serve the server without problem so I'm pretty sure everything should be there. Maybe another problem with the path in Windows 10? I'll try to find a solution and post it here if I found something

from play-ng2-webpack2.

ronniegane avatar ronniegane commented on August 20, 2024

I'm having the same problem. After changing the path for the process called in afterStarted, I can compile. But the front-end files (JS, CSS etc) are not created at /public/ui. It seems like the npm process isn't actually running at the same time as the sbt process.

Workaround for now is just opening another command terminal in /ui subfolder and running npm run build -- --watch there directly. If you do that before you run sbt run in the root folder, the resource files will be there.
I'll update if I figure out how to get it to work automatically. It'll just be some quirk of windows.
The project works flawlessly on OSX, but unfortunately one of my colleagues is attached to his windows machine...

from play-ng2-webpack2.

ronniegane avatar ronniegane commented on August 20, 2024

Okay, I think I got it!
From this post where someone is using webpack and sbt in Windows, I found the magic phrase:

cmd /c which executes the string following it and then terminates.

if I prefix the script call to npm with this, then it works as expected- sbt run from root directory kicks off npm run build which does ng build to the /public/ui folder. All assets available at localhost:9000 where they should be.

I tried deleting node_modules as well to check if the cmd /c prefix works for that script as well, and it does. It doesn't provide much feedback though- so it looks like the script has frozen for a few minutes until all your node modules appear at once.

So a proper fix to make the runHooks work in a Windows environment, is to change UIBuild.scala:

      override def beforeStarted(): Unit = {
        if (!(base / "ui" / "node_modules").exists()) Process("cmd /c npm install", base / "ui").!
      }

      override def afterStarted(addr: InetSocketAddress): Unit = {
        process = Option(
          Process("cmd /c npm run build -- --watch", base / "ui").run
        )
      }

you'd probably want to use part of @hatemismail 's solution to check the OS and run these altered commands only in Windows. It's pretty late now but if you like I can make a pull request in the next few days, it's only a few lines.

from play-ng2-webpack2.

lbialy avatar lbialy commented on August 20, 2024

I'll look into this (and hopefully integrate your solution) during Easter, sorry for delay. If you have a working solution ready you can open a PR and I'll be happy to accept it.

from play-ng2-webpack2.

ronniegane avatar ronniegane commented on August 20, 2024

Yeah I'll try and collate my fixes into a PR today.

from play-ng2-webpack2.

lbialy avatar lbialy commented on August 20, 2024

Thank you kindly!

from play-ng2-webpack2.

ronniegane avatar ronniegane commented on August 20, 2024

Pull request made: #6

from play-ng2-webpack2.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.