Skip to content

Commit dfd5413

Browse files
committed
tech(systemjs): worked on making optimized builds work with systemjs builder
1 parent 93e424d commit dfd5413

File tree

11 files changed

+55
-36
lines changed

11 files changed

+55
-36
lines changed

public/app/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
define([
2-
'./app2'
2+
'./grafana'
33
], function(app) {
44
'use strict';
55
// backward compatability hack;
6+
console.log(app);
67
return app.default;
78
});

public/app/app2.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

public/app/boot.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(function bootGrafana() {
2+
'use strict';
3+
4+
System.import('app/app').then(function(app) {
5+
console.log(app);
6+
app.init();
7+
}).catch(function(err) {
8+
console.log('Loading app module failed: ', err);
9+
});
10+
11+
})();

public/app/grafana_app.ts renamed to public/app/grafana.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,6 @@ export class GrafanaApp {
9393
console.log('Application boot failed:', err);
9494
});
9595
}
96-
}
96+
}
9797

98+
export default new GrafanaApp();

public/app/systemjs.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ System.config({
4141

4242
meta: {
4343
'vendor/angular/angular.js': {
44-
format: 'amd',
44+
format: 'global',
4545
deps: ['jquery'],
4646
exports: 'angular',
4747
},

public/views/index.html

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,14 @@
5757
};
5858
</script>
5959

60-
<!-- build:js [[.AppSubUrl]]/public/app/app.js -->
60+
<!-- build:js [[.AppSubUrl]]/public/app/boot.js -->
6161
<script src="[[.AppSubUrl]]/public/vendor/npm/es6-shim/es6-shim.js"></script>
6262
<script src="[[.AppSubUrl]]/public/vendor/npm/es6-promise/dist/es6-promise.js"></script>
6363
<script src="[[.AppSubUrl]]/public/vendor/npm/systemjs/dist/system.src.js"></script>
64-
<script src="[[.AppSubUrl]]/public/vendor/npm/rxjs/bundles/Rx.js"></script>
65-
<script src="[[.AppSubUrl]]/public/vendor/npm/angular2/bundles/angular2-polyfills.js"></script>
66-
<script src="[[.AppSubUrl]]/public/vendor/npm/angular2/bundles/angular2.dev.js"></script>
6764
<script src="[[.AppSubUrl]]/public/app/systemjs.conf.js"></script>
65+
<script src="[[.AppSubUrl]]/public/app/boot.js"></script>
6866
<!-- endbuild -->
6967

70-
<script>
71-
System.import('app/app').then(function(app) {
72-
console.log(app)
73-
app.init();
74-
}).catch(function(err) {
75-
console.log('Loading app module failed: ', err);
76-
});
77-
</script>
78-
7968
[[if .GoogleAnalyticsId]]
8069
<script>
8170
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

tasks/build_task.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@ module.exports = function(grunt) {
1010
'clean:release',
1111
'copy:public_to_gen',
1212
'typescript:build',
13-
'karma:test',
13+
// 'karma:test',
1414
'phantomjs',
1515
'css',
16-
// 'htmlmin:build',
16+
'htmlmin:build',
1717
'ngtemplates',
1818
'cssmin:build',
1919
'ngAnnotate:build',
20-
'requirejs:build',
20+
'systemjs:build',
2121
'concat:js',
22-
'clean:temp',
23-
'filerev',
24-
'remapFilerev',
22+
// 'filerev',
23+
// 'remapFilerev',
2524
'usemin',
26-
'uglify:genDir'
25+
// 'uglify:genDir'
2726
]);
2827

2928
// task to add [[.AppSubUrl]] to reved path

tasks/options/concat.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = function(config) {
1313
],
1414
dest: '<%= genDir %>/css/grafana.dark.min.css'
1515
},
16+
1617
cssLight: {
1718
src: [
1819
'<%= genDir %>/vendor/css/normalize.min.css',
@@ -24,13 +25,24 @@ module.exports = function(config) {
2425
],
2526
dest: '<%= genDir %>/css/grafana.light.min.css'
2627
},
28+
2729
js: {
2830
src: [
29-
'<%= tempDir %>/vendor/requirejs/require.js',
30-
'<%= tempDir %>/app/require_config.js',
31-
'<%= tempDir %>/app/app.js',
31+
'<%= genDir %>/vendor/npm/es6-shim/es6-shim.js',
32+
'<%= genDir %>/vendor/npm/es6-promise/es6-promise.js',
33+
'<%= genDir %>/vendor/npm/systemjs/dist/system.js',
34+
'<%= genDir %>/app/systemjs.conf.js',
35+
'<%= genDir %>/app/boot.js',
36+
],
37+
dest: '<%= genDir %>/app/boot.js'
38+
},
39+
40+
bundle_and_boot: {
41+
src: [
42+
'<%= genDir %>/app/app_bundle.js',
43+
'<%= genDir %>/app/boot.js',
3244
],
33-
dest: '<%= genDir %>/app/app.js'
45+
dest: '<%= genDir %>/app/boot.js'
3446
},
3547
};
3648
};

tasks/options/cssmin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = function(config) {
33
build: {
44
expand: true,
55
cwd: '<%= genDir %>',
6-
src: '**/*.css',
6+
src: ['css/*.css', 'vendor/css/*.css'],
77
dest: '<%= genDir %>'
88
}
99
};

tasks/options/ngtemplates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = function(config) {
77
options: {
88
bootstrap: function(module, script) {
99
return "define('app/core/partials', ['app/core/core_module'], function(coreModule) { \n" +
10-
"coreModule.run(['$templateCache', function($templateCache) { \n" +
10+
"coreModule.default.run(['$templateCache', function($templateCache) { \n" +
1111
script +
1212
'\n}]);' +
1313
'\n});';

tasks/systemjs_task.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module.exports = function(grunt) {
22
"use strict";
33

44
grunt.registerTask('systemjs:build', function() {
5-
var path = require("path");
65
var Builder = require('systemjs-builder');
76
var done = this.async();
87

@@ -11,17 +10,28 @@ module.exports = function(grunt) {
1110
var builder = new Builder('public_gen', 'public_gen/app/systemjs.conf.js');
1211
console.log('Starting systemjs-builder');
1312

13+
var modules = [
14+
'app/app',
15+
'app/features/all',
16+
'app/plugins/panels/**/*',
17+
'app/plugins/datasource/graphite/**/*',
18+
'app/plugins/datasource/influxdb/**/*',
19+
'app/plugins/datasource/elasticsearch/**/*',
20+
];
21+
22+
var expression = modules.join(' + ');
23+
1424
builder
15-
.bundle('app/app + app/features/all', 'public_gen/app/app.js')
25+
.bundle(expression, 'public_gen/app/app_bundle.js')
1626
.then(function() {
1727
console.log('Build complete');
1828
done();
29+
grunt.task.run('concat:bundle_and_boot');
1930
})
2031
.catch(function(err) {
2132
console.log('Build error');
2233
console.log(err);
2334
done();
2435
});
2536
});
26-
2737
};

0 commit comments

Comments
 (0)