I have a front-end SPA using RequireJS
(2.1.14) as module system. It basically bootstrap and load Backbone.Marionette
app.
In main
It is not possible to use RequireJS on the client (browser) to access files from node_modules.
Files under node_modules
must first be copied to a location that is accessible (under the public
folder) before the client can access them. The documentation says RequireJS can access Node modules, but this only works for server-side JavaScript (when you want to use RequireJS-style module syntax in Node).
To use your config
module in the client app, you must first transform it into a RequireJS-compatible module and copy it under public
. This article explains how to automate this with package managers and build tools, and contains the quote that finally fixed my broken understanding of RequireJS + Node:
In order to use node modules on the browser you will need a build tool. This might bother you. If this is a deal breaker then by all means continue wasting your life copying and pasting code and arranging your script tags.