javascript - Require.js and r.js include all dependencies even of submodules -
i'm using require.js first time , working pretty moment. however, started wanting make build. idea create 1 file js , templates. however, every time use r.js includes dependencies of main module.
here app.build.js:
({ appdir: "public/javascripts", baseurl: ".", dir: "build", paths: { "hbs": "lib/hbs", "jquery": "lib/jquery", "handlebars": "lib/handlebars", "backbone": "lib/backbone", "underscore": "lib/underscore", "bootstrap": "lib/bootstrap.min.js" }, modules: [{name: "main"}], shim: { "bootstrap": { deps: ["jquery"], exports: "$.fn.popover" }, underscore: { exports: '_' }, 'handlebars': { exports: 'handlebars' }, backbone: { deps: ["underscore", "jquery"], exports: "backbone" } }})
the beginning of main.js:
require.config({ paths: { "hbs": "lib/hbs", "handlebars": "lib/handlebars", "backbone": "lib/backbone", "underscore": "lib/underscore", "jquery": "lib/jquery", "bootstrap": "lib/bootstrap.min.js" }, hbs: { disablei18n: true }, shim: { "bootstrap": { deps: ["jquery"], exports: "$.fn.popover" }, underscore: { exports: '_' }, 'handlebars': { exports: 'handlebars' }, backbone: { deps: ["underscore", "jquery"], exports: "backbone" } } }); require(['jquery', 'backbone', 'videos'], function($, backbone, videos) { // whatever });
in case final file created in build 'main.js' contains: jquery, underscore, backbone , videos. how can make sure includes dependencies of module videos
namely: template 'hbs!template/videos/show'. how can make sure bootstrap.min.js added though it's not required anywhere? should remove require.config define paths not supposed anymore modules in final file?
in app.build.js include link main config file , can remove specified modules, should include dependencies used main module.
({ ... mainconfigfile: 'main.js', ... })
you may skip paths , shim, since specified in main. bellow sample config i'm using in 1 of projects , works charm:
({ name: 'main', baseurl: '../', // optimize: 'none', optimize: 'uglify2', exclude: ['jquery'], paths: { requirelib: 'require' }, mainconfigfile: '../main.js', out: '../main.min.js', // function if defined called every file read in // build done trace js dependencies. // remove references console.log(...) onbuildread: function (modulename, path, contents) { return contents; // return contents.replace(/console.log(.*);/g, ''); } })
Comments
Post a Comment