You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RequireJS supports loader plugins, which allow your AMD modules to specify dependencies that aren't AMD modules, by prefixing the path with the plugin name followed by !.
rvc is one such loader plugin, and it allows you to require component files.
Clone the repo: $ git clone https://github.com/ractivejs/rvc.git.
Usage
First, RequireJS needs to be able to find rvc.js and ractive.js. Either it should be in the root of your project (or whatever baseUrl is configured to be), or you'll need to set up the paths config (obviously, change the paths as appropriate):
Once RequireJS is configured, you can import components like so:
// At the top-level of your app, e.g. inside your main.js filerequire(['rvc!foo'],function(Foo){varractive=newFoo({/* ... */});});// Inside a moduledefine(['rvc!foo'],function(Foo){varractive=newFoo({/* ... */});});
Note that the .html file extension is omitted - this is assumed.
Component paths work just like regular module paths, so they can be relative (rvc!../foo), or below an entry in the paths config:
The great feature of RequireJS is that while you can develop your app without having to rebuild it every time you change a file, you can also bundle it into a single file for production using the optimiser.
In addition to this 'inlining' of your components, rvc will parse your templates so that no additional computation needs to happen in the browser.
Once your project is optimised, you don't need the plugin itself, so add rvc to the stubModules option: