GithubHelp home page GithubHelp logo

rvc's Introduction

rvc.js

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.

If you're not sure what 'component files' are, have a read of this. If you're not familiar with RequireJS loader plugins, there's some documentation here.

Installation

To get rvc.min.js you can:

  • Use CDN: //cdn.jsdelivr.net/ractive.rvc/latest/rvc.min.js.
  • Use bower: $ bower i rvc.
  • Download the latest release.
  • 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):

require.config({
  paths: {
    ractive: 'lib/ractive',
    rvc: 'plugins/rvc'
  }
});

Once RequireJS is configured, you can import components like so:

// At the top-level of your app, e.g. inside your main.js file
require([ 'rvc!foo' ], function ( Foo ) {
  var ractive = new Foo({ /* ... */ });
});

// Inside a module
define([ 'rvc!foo' ], function ( Foo ) {
  var ractive = new Foo({ /* ... */ });
});

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:

require.config({
  paths: {
    ractive: 'lib/ractive',
    rvc: 'plugins/rvc',
    ui: 'path/to/ractive_components'
  }
});

require([ 'rvc!ui/foo' ], function ( Foo ) {
  var ractive = new Foo({ /* ... */ });
});

Optimisation

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:

// optimiser config
{
  paths: {
    ractive: 'lib/ractive',
    rvc: 'plugins/rvc'
  },
  stubModules: [ 'rvc' ]
}

Consult the documentation for more information on using the optimiser.

License

MIT.

rvc's People

Contributors

defnull avatar fskreuz avatar inhuman-cpc avatar ken-gladeye avatar martinkolarik avatar rich-harris avatar

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.