requirejs.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. ]
  57. }
  58. ];
  59. var fs = require('fs');
  60. var panelPath = config.srcDir+'/app/panels'
  61. // create a module for each directory in src/app/panels/
  62. fs.readdirSync(panelPath).forEach(function (panelName) {
  63. if(!grunt.file.exists(panelPath+'/'+panelName+'/module.js')) {
  64. fs.readdirSync(panelPath+"/"+panelName).forEach(function (subName) {
  65. requireModules.push({
  66. name: 'panels/'+panelName+'/'+subName+'/module',
  67. exclude: ['app']
  68. }); })
  69. } else {
  70. requireModules.push({
  71. name: 'panels/'+panelName+'/module',
  72. exclude: ['app']
  73. });
  74. }
  75. });
  76. // exclude the literal config definition from all modules
  77. requireModules
  78. .forEach(function (module) {
  79. module.excludeShallow = module.excludeShallow || [];
  80. module.excludeShallow.push('config');
  81. });
  82. return _c;
  83. };