Code Monkey home page Code Monkey logo

rs_require's Introduction

rs_require

Build status

Simple amd-loader written on Rapydscript.

Usage:

...
<script src="rs_require.js"></script>
<script src="index.js"></script>
...

or

...
<script src="rs_require.js" data-main = "path/to/index.js"></script>
...
//index.js
define(['vue', 'vue-router'], function(vue, v_router){
    ... // do something using vue and v_router
});

if some configuration is required

//index.js
define(['amd'], function(amd){
    // amd is special built-in module with props: {version, config, import}
    amd.config({
        base_url: 'main_path/to/scripts' // default is parent location of data-main (if set) or rs_require.js 
        path:{
            'here': 'path/to/there',
            'cdnjs': 'https://cdnjs.cloudflare.com/ajax/libs' // so you can: define(['cdnjs/vue/2.6.12/vue.min.js'], function(vue){...})
        },
        map:{
            'here/this_module':'path/to/there/that_module' 
        }
        // or  
        // map: function(path_to_module, requester){ ...; return mapped_path_to_module}
        // requester is 'path/to/requester_module' that asks path_to_module
    });
    amd.import('app'); // start main code
    //or assuming app-module returns class   
    amd.import('app').then(App => {
        const app = new App(); 
        app.mount('#app');
        ... 
    })
});

also, instead of traditional define(['a','b','c'], function(a, b, c)) you can

define(['amd'], function(amd){
    amd.import({
        'path/to/vue':'',   // in case of empty string, the module name in package will be the tail of the path 
        'path/to/vue-router':'v_router'
    }).then(pack = > {
        pack.vue
        pack.v_router
    })
}) 

or

define({
        'path/to/vue':'',
        'path/to/vue-router':'v_router'
    }, 
    function(pack){
        pack.vue
        pack.v_router
    }
) 

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.