sbt-play-gulp icon indicating copy to clipboard operation
sbt-play-gulp copied to clipboard

Serve gulp files from dynamic URI

Open miguelCT opened this issue 8 years ago • 1 comments

Hi,

I've been using the plugin for a few weeks and everything seem to work fine. However there's something that I'm missing in the plugin.

Context

I'm using gulp to call webpack in order to build the javascript bundle and index.html and generate the output files into the dist/ folder. Also, I have configured the sbt-play-gulp plugin to always search for the static files into ui/dist.

That works as intender but my problem came when I wanted to use webpack-dev-server to make the webpack builds faster in developement. This webpack-dev-server starts another server and builds the webpack files in memory, without generating output files to dist/ folder. Play! expects to have the gulp(webpack) output files in the dist/ folder but, as I've mentioned, the webpack-dev-server does not generates any files on disk, so Play can't serve any static files because there are no static built files in that folder in developement.

Regarding on a possible solution, I wonder if it could be possible to extend plugin logic to be able to resolve files not only from static directories (.tmp/serve, /dist, etc) but also from dynamic URI's, pointing to another server, for example. It might be great if this configuration could be set in a similar way as follows:

gulp.devDirs=["ui/dist", "http://localhost:8080/dist"]

The idea would be, if a requested file is not found in the static directories, then fetch the requested file from the specified url. Maybe that would fit in this point of the plugin: https://github.com/mmizutani/sbt-play-gulp/blob/master/play-gulp/app/com/github/mmizutani/playgulp/GulpAssets.scala#L91

This idea is similar than the explained in this post: http://stackoverflow.com/a/33386933, where it says to set the main server (Play) as a proxy to the webpack-dev-server:

You can use a hybrid approach, which essentially setup the webpack-dev-server as a proxy. You have your express server that serves everything except for assets. If it's an asset, the request gets forwarded/proxied to the webpack-dev-server. [...]

Having said that, do you think this would be an interesting improvement to the plugin? And if you do, do you think it could be done relatively easily or it may take some time to develope it?

PD: I'm not a scala or java developer so I'm not sure I could provide a PR in short time.

miguelCT avatar May 09 '16 16:05 miguelCT