requirejs.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. module.exports = function(config,grunt) {
  2. 'use strict';
  3. function buildRequireJsOptions() {
  4. var options = {
  5. appDir: '<%= genDir %>',
  6. dir: '<%= tempDir %>',
  7. mainConfigFile: '<%= genDir %>/app/require_config.js',
  8. baseUrl: './',
  9. waitSeconds: 0,
  10. modules: [], // populated below,
  11. optimize: 'none',
  12. optimizeCss: 'none',
  13. optimizeAllPluginResources: false,
  14. removeCombined: true,
  15. findNestedDependencies: true,
  16. normalizeDirDefines: 'all',
  17. inlineText: true,
  18. skipPragmas: true,
  19. done: function (done, output) {
  20. var duplicates = require('rjs-build-analysis').duplicates(output);
  21. if (duplicates.length > 0) {
  22. grunt.log.subhead('Duplicates found in requirejs build:');
  23. grunt.log.warn(duplicates);
  24. done(new Error('r.js built duplicate modules, please check the excludes option.'));
  25. }
  26. done();
  27. }
  28. };
  29. // setup the modules require will build
  30. var requireModules = options.modules = [
  31. {
  32. // main/common module
  33. name: 'app/app',
  34. include: [
  35. 'text',
  36. 'jquery',
  37. 'bootstrap',
  38. 'modernizr',
  39. 'timepicker',
  40. 'datepicker',
  41. 'jquery.flot',
  42. 'angular-strap',
  43. 'angular-dragdrop',
  44. 'app/core/core',
  45. 'app/features/all',
  46. // bundle the datasources
  47. 'app/plugins/datasource/grafana/datasource',
  48. 'app/plugins/datasource/graphite/datasource',
  49. 'app/plugins/datasource/elasticsearch/datasource',
  50. 'app/plugins/datasource/influxdb/datasource',
  51. ]
  52. },
  53. ];
  54. var fs = require('fs');
  55. var panelPath = config.srcDir + '/app/plugins/panel';
  56. // create a module for each directory in public/app/panel/
  57. fs.readdirSync(panelPath).forEach(function (panelName) {
  58. requireModules[0].include.push('app/plugins/panel/'+panelName+'/module');
  59. });
  60. return { options: options };
  61. }
  62. return { build: buildRequireJsOptions() };
  63. };