Skip to content

Commit b463573

Browse files
committed
tech(webpack): testing webpack
1 parent 1900c81 commit b463573

File tree

13 files changed

+125
-58
lines changed

13 files changed

+125
-58
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
"grunt-sync": "^0.4.1",
6767
"karma-sinon": "^1.0.3",
6868
"lodash": "^2.4.1",
69-
"sinon": "1.10.3"
69+
"sinon": "1.10.3",
70+
"ts-loader": "^0.5.5",
71+
"webpack": "^1.12.1"
7072
}
7173
}

public/app/app.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ define([
1515
'angular-ui',
1616
'extend-jquery',
1717
'bindonce',
18+
'./core/core',
19+
'./services/all',
20+
'./features/all',
21+
'./controllers/all',
22+
'./directives/all',
23+
'./components/partials',
24+
'./routes/all',
1825
],
1926
function (angular, $, _, appLevelRequire) {
2027

@@ -80,49 +87,42 @@ function (angular, $, _, appLevelRequire) {
8087
});
8188

8289
var preBootRequires = [
83-
'core/core',
84-
'services/all',
85-
'features/all',
86-
'controllers/all',
87-
'directives/all',
88-
'components/partials',
89-
'routes/all',
9090
];
9191

9292
app.boot = function() {
93-
require(preBootRequires, function () {
93+
// disable tool tip animation
94+
$.fn.tooltip.defaults.animation = false;
9495

95-
// disable tool tip animation
96-
$.fn.tooltip.defaults.animation = false;
96+
// bootstrap the app
97+
angular
98+
.element(document)
99+
.ready(function() {
100+
angular.bootstrap(document, apps_deps)
101+
.invoke(['$rootScope', function ($rootScope) {
102+
_.each(pre_boot_modules, function (module) {
103+
_.extend(module, register_fns);
104+
});
97105

98-
// bootstrap the app
99-
angular
100-
.element(document)
101-
.ready(function() {
102-
angular.bootstrap(document, apps_deps)
103-
.invoke(['$rootScope', function ($rootScope) {
104-
_.each(pre_boot_modules, function (module) {
105-
_.extend(module, register_fns);
106+
pre_boot_modules = false;
107+
$rootScope.requireContext = appLevelRequire;
108+
$rootScope.require = function (deps, fn) {
109+
var $scope = this;
110+
$scope.requireContext(deps, function () {
111+
var deps = _.toArray(arguments);
112+
// Check that this is a valid scope.
113+
if($scope.$id) {
114+
$scope.$apply(function () {
115+
fn.apply($scope, deps);
106116
});
107-
108-
pre_boot_modules = false;
109-
$rootScope.requireContext = appLevelRequire;
110-
$rootScope.require = function (deps, fn) {
111-
var $scope = this;
112-
$scope.requireContext(deps, function () {
113-
var deps = _.toArray(arguments);
114-
// Check that this is a valid scope.
115-
if($scope.$id) {
116-
$scope.$apply(function () {
117-
fn.apply($scope, deps);
118-
});
119-
}
120-
});
121-
};
122-
}]);
123-
});
117+
}
118+
});
119+
};
120+
}]);
124121
});
125122
};
126123

124+
console.log('booting');
125+
app.boot();
126+
127127
return app;
128128
});

public/app/controllers/errorCtrl.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
define([
22
'angular',
3-
'app',
43
'lodash'
54
],
65
function (angular) {

public/app/controllers/pulldown.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
define([
22
'angular',
3-
'app',
43
'lodash'
54
],
6-
function (angular, app, _) {
5+
function (angular, _) {
76
'use strict';
87

98
var module = angular.module('grafana.controllers');
@@ -39,4 +38,4 @@ function (angular, app, _) {
3938

4039
});
4140

42-
});
41+
});

public/app/directives/dropdown.typeahead.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
define([
22
'angular',
3-
'app',
43
'lodash',
54
'jquery',
65
],
7-
function (angular, app, _, $) {
6+
function (angular, _, $) {
87
'use strict';
98

109
angular

public/app/directives/metric.segment.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
define([
22
'angular',
3-
'app',
43
'lodash',
54
'jquery',
65
],
7-
function (angular, app, _, $) {
6+
function (angular, _, $) {
87
'use strict';
98

109
angular

public/app/directives/valueSelectDropdown.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
define([
22
'angular',
3-
'app',
43
'lodash',
54
'jquery',
65
],
7-
function (angular, app, _) {
6+
function (angular, _) {
87
'use strict';
98

109
angular

public/app/features/dashboard/graphiteImportCtrl.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
define([
22
'angular',
3-
'app',
43
'lodash',
54
'kbn'
65
],
7-
function (angular, app, _, kbn) {
6+
function (angular, _, kbn) {
87
'use strict';
98

109
var module = angular.module('grafana.controllers');

public/app/features/dashboard/rowCtrl.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
define([
22
'angular',
3-
'app',
43
'lodash',
54
'config'
65
],
7-
function (angular, app, _, config) {
6+
function (angular, _, config) {
87
'use strict';
98

109
var module = angular.module('grafana.controllers');

public/app/plugins/datasource/graphite/addGraphiteFunc.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
define([
22
'angular',
3-
'app',
43
'lodash',
54
'jquery',
65
'./gfunc',
76
],
8-
function (angular, app, _, $, gfunc) {
7+
function (angular, _, $, gfunc) {
98
'use strict';
109

1110
angular
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
define([
22
'angular',
3-
'../vendor/angular-ui/tabs',
3+
'./tabs',
44
], function() {
55
});
66

public/views/index.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
<base href="[[.AppSubUrl]]/" />
1919

2020
<!-- build:js [[.AppSubUrl]]/app/app.js -->
21-
<script src="[[.AppSubUrl]]/public/vendor/requirejs/require.js"></script>
22-
<script src="[[.AppSubUrl]]/public/app/components/require.config.js"></script>
21+
<script src="[[.AppSubUrl]]/public/app/bundle.js"></script>
2322
<!-- endbuild -->
2423
</head>
2524

@@ -53,9 +52,9 @@
5352
settings: [[.Settings]],
5453
};
5554

56-
require(['app'], function (app) {
57-
app.boot();
58-
})
55+
// require(['app'], function (app) {
56+
// app.boot();
57+
// })
5958
</script>
6059

6160
[[if .GoogleAnalyticsId]]

webpack.config.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
'use strict';
2+
3+
var webpack = require('webpack');
4+
var path = require('path');
5+
6+
function absDir(relative) {
7+
return path.join(__dirname, 'public_gen', relative);
8+
}
9+
10+
var webpackConfig = {
11+
context: __dirname + '/public_gen/app/',
12+
entry: {
13+
'app' : './app.js',
14+
},
15+
output: {
16+
path: __dirname + '/public_gen/app/',
17+
filename: 'bundle.js',
18+
},
19+
plugins: [
20+
// This replaces shim stuff in RequireJS.
21+
new webpack.ProvidePlugin({
22+
$: "jquery",
23+
jQuery: "jquery",
24+
"windows.jQuery": "jquery",
25+
})
26+
],
27+
module: {
28+
unknownContextRegExp: /$^/,
29+
noParse: [
30+
/\.html/,
31+
/\.ts/,
32+
/\.map/,
33+
/cloudwatch/,
34+
/app\/panels/,
35+
/\.json/,
36+
/moment\.js/
37+
],
38+
// so that JSX can be used.
39+
loaders: [
40+
]
41+
},
42+
resolve: {
43+
alias: {
44+
"kbn": absDir('/app/components/kbn.js'),
45+
"extend-jquery": absDir('/app/components/extend-jquery.js'),
46+
"lodash": absDir('/app/components/lodash.extended.js'),
47+
"settings": absDir('/app/components/settings.js'),
48+
"config": absDir('/app/components/config.js'),
49+
"store": absDir('/app/components/store.js'),
50+
"app": absDir('/app/app.js'),
51+
"aws-sdk": absDir('/vendor/aws-sdk/dist/aws-sdk.js'),
52+
"angular": absDir('/vendor/angular/angular.js'),
53+
"angular-ui": absDir('/vendor/angular-ui/angular-bootstrap.js'),
54+
"angular-dragdrop": absDir('/vendor/angular-native-dragdrop/draganddrop.js'),
55+
"angular-sanitize": absDir('/vendor/angular-sanitize/angular-sanitize.js'),
56+
"angular-route": absDir('/vendor/angular-route/angular-route.js'),
57+
"angular-strap": absDir('/vendor/angular-other/angular-strap.js'),
58+
"moment": absDir('/vendor/moment.js'),
59+
"bootstrap": absDir('/vendor/bootstrap/bootstrap.js'),
60+
"jquery": absDir('/vendor/jquery/dist/jquery.js'),
61+
"filesaver": absDir('/vendor/filesaver.js'),
62+
"ZeroClipboard": absDir('/vendor/ZeroClipboard.js'),
63+
"bootstrap-tagsinput": absDir('/vendor/tagsinput/bootstrap-tagsinput.js'),
64+
"spectrum": absDir('/vendor/spectrum.js'),
65+
"lodash-src": absDir('/vendor/lodash.js'),
66+
"bindonce": absDir('/vendor/angular-bindonce/bindonce.js'),
67+
},
68+
root: [
69+
__dirname + '/public_gen',
70+
],
71+
}
72+
};
73+
74+
module.exports = webpackConfig;

0 commit comments

Comments
 (0)