requirejs.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/services/all',
  46. 'app/features/all',
  47. 'app/controllers/all',
  48. // bundle the datasources
  49. 'app/plugins/datasource/grafana/datasource',
  50. 'app/plugins/datasource/graphite/datasource',
  51. 'app/plugins/datasource/influxdb/datasource',
  52. ]
  53. },
  54. ];
  55. var fs = require('fs');
  56. var panelPath = config.srcDir + '/app/panels';
  57. // create a module for each directory in public/app/panels/
  58. fs.readdirSync(panelPath).forEach(function (panelName) {
  59. requireModules[0].include.push('app/panels/'+panelName+'/module');
  60. });
  61. return { options: options };
  62. }
  63. return { build: buildRequireJsOptions() };
  64. };