Configuring CLI for a existing web server


Hey I have several legacy JSPM projects and have considered moving them to the new CLI. Are there any articles or information about configuring the CLI generated webpack projects to be served from an external html page?

For instance if I have a Rails application that serves an app with CSRF tokens and all the goodies and want to load the JavaScript as an app within the page without having the index.html modified in any way.

Thanks in advance,



I don’t know webpack, but I have a setup in cli+requirejs that uses http-proxy-middleware to hook up a backend. It might be useful to your use case.


Beware of Rails, you need to reload CRRF token. For security reason, rails regenerates the token when user login/logout.

I have used a fix here before with jquery ajax, it should be very similar if to use fetch api. It basically reload the token without reloading the whole page, then uses the token manually on next request header.

Update: just checked my code, I was using Sija’s snippet.


Yeah I have the CSRF token reload already done (the application was has been around for about two years) just need to figure out how to get a CLI project building so it can be included. I’ll look at the require.js setup you have.

The CLI with Webpack in particular seems to generate an index.html on the fly.



So it sounds like no one has gone down the path before with webpack, I don’t want to be the first so I’ll research the other CLI options instead.

Thanks again for the help!


So as a final wrap-up here the issue with Webpack looked like too large a task to take on so instead I tried to get the CLI configured to both output in to a sub-directory as well set up a base URL for the system.js config.js file.

Since Rails serves out of a directory called public that does not actually exist in the path when requesting I could not find a combination of options to handle this, so instead I’m building to a directory minus public (ex. scripts) and then using the copyFiles directive to copy them to the public/scripts/ directory. The problem here is that copyFiles happens before the build as best I can tell so the files are always 1 iteration behind. But it’s better than nothing!