Loading Bootstrap from CDN with Require.js

后端 未结 1 953
无人及你
无人及你 2020-12-07 10:23

Bootstrap is distributed in CDN in

http://www.bootstrapcdn.com/

  • Is it possible to load Bootstrap with Require.JS 2.x (shimmed or native AMD)?

    <
1条回答
  •  半阙折子戏
    2020-12-07 10:39

    requirejs.config({
        appDir: ".",
        baseUrl: "js",
        paths: { 
            /* Load jquery from google cdn. On fail, load local file. */
            'jquery': ['//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min', 'libs/jquery-min'],
            /* Load bootstrap from cdn. On fail, load local file. */
            'bootstrap': ['//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.', 'libs/bootstrap-min']
        },
        shim: {
            /* Set bootstrap dependencies (just jQuery) */
            'bootstrap' : ['jquery']
        }
    });
    
    require(['jquery', 'bootstrap'], function($) {
        console.log("Loaded :)");    
        return {};
    });
    

    0 讨论(0)
提交回复
热议问题