requirejs.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. module.exports = function(config,grunt) {
  2. var _c = {
  3. build: {
  4. options: {
  5. appDir: '<%= tempDir %>',
  6. dir: '<%= destDir %>',
  7. mainConfigFile: '<%= tempDir %>/app/components/require.config.js',
  8. modules: [], // populated below
  9. optimize: 'none',
  10. optimizeCss: 'none',
  11. optimizeAllPluginResources: false,
  12. paths: { config: '../config.sample' }, // fix, fallbacks need to be specified
  13. removeCombined: true,
  14. findNestedDependencies: true,
  15. normalizeDirDefines: 'all',
  16. inlineText: true,
  17. skipPragmas: true,
  18. done: function (done, output) {
  19. var duplicates = require('rjs-build-analysis').duplicates(output);
  20. if (duplicates.length > 0) {
  21. grunt.log.subhead('Duplicates found in requirejs build:');
  22. grunt.log.warn(duplicates);
  23. done(new Error('r.js built duplicate modules, please check the excludes option.'));
  24. }
  25. done();
  26. }
  27. }
  28. }
  29. };
  30. // setup the modules require will build
  31. var requireModules = _c.build.options.modules = [
  32. {
  33. // main/common module
  34. name: 'app',
  35. include: [
  36. 'css',
  37. 'kbn',
  38. 'text',
  39. 'jquery',
  40. 'angular',
  41. 'settings',
  42. 'bootstrap',
  43. 'modernizr',
  44. 'elasticjs',
  45. 'timepicker',
  46. 'datepicker',
  47. 'underscore',
  48. 'filters/all',
  49. 'jquery.flot',
  50. 'services/all',
  51. 'angular-strap',
  52. 'directives/all',
  53. 'jquery.flot.pie',
  54. 'angular-sanitize',
  55. 'angular-dragdrop',
  56. 'panels/graphite/module',
  57. 'panels/text/module',
  58. 'panels/timepicker/module'
  59. ]
  60. }
  61. ];
  62. var fs = require('fs');
  63. var panelPath = config.srcDir+'/app/panels'
  64. // create a module for each directory in src/app/panels/
  65. fs.readdirSync(panelPath).forEach(function (panelName) {
  66. if(!grunt.file.exists(panelPath+'/'+panelName+'/module.js')) {
  67. fs.readdirSync(panelPath+"/"+panelName).forEach(function (subName) {
  68. requireModules.push({
  69. name: 'panels/'+panelName+'/'+subName+'/module',
  70. exclude: ['app']
  71. });
  72. })
  73. } else {
  74. requireModules.push({
  75. name: 'panels/'+panelName+'/module',
  76. exclude: ['app']
  77. });
  78. }
  79. });
  80. // exclude the literal config definition from all modules
  81. requireModules
  82. .forEach(function (module) {
  83. module.excludeShallow = module.excludeShallow || [];
  84. module.excludeShallow.push('config');
  85. });
  86. return _c;
  87. };