Skip to content
This repository was archived by the owner on Dec 3, 2023. It is now read-only.

Commit bea1442

Browse files
committed
Inject angular where window.angular is used.
This should work, but it does. It should make angular.js recurse but webpack takes care of it. Many thanks to @huston007 for this even though I didn't merge #17.
1 parent 4e4973a commit bea1442

File tree

19 files changed

+137
-13
lines changed

19 files changed

+137
-13
lines changed

README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,47 @@ Makes webpack aware of AngularJS modules.
55
## Getting Started
66
This project is just getting off the ground.
77

8-
It is at the stage now where you can use it to get angular apps webpacked without needing `require()` in your code, but it does it by trying to map between angular module names and file names. The conventions for doing this are various, so it will not fit all cases. Please submit an issue on github if it isn't working for your modules and I'll try to iron out the wrinkles over time.
8+
It is at the stage now where you can use it to get angular apps webpacked
9+
without needing `require()` in your code, but it does it by trying to map
10+
between angular module names and file names. The conventions for doing this are
11+
various, so it will not fit all cases. Please submit an issue on github if it
12+
isn't working for your modules and I'll try to iron out the wrinkles over time.
913

1014
To see it in action, I've [forked the angular-seed project](https://github.com/stackfull/angular-seed)
1115

16+
## Development
17+
18+
Given how complex the problem is, regular test frameworks can't help much. I've
19+
developed a small grunt task to run compile scenarios and check the output. It's
20+
less than ideal and a little fragile. To add new scenarios, create a directory
21+
in test/scenarios containing a webpack.conf.js config file, an `in` and an `out`
22+
directory. The `in` directory will be used as the source and the output will
23+
be compared against `out/bundle.js` (ignoring comments etc.).
24+
25+
To run the scenarios::
26+
27+
grunt webpackScenario
28+
29+
by default, it won't show what the output was when it doesn't match, so use
30+
31+
grunt --debug webpackScenario
32+
33+
In addition, karma tests in the `verify` directory check that the output makes
34+
a viable executable using the `karma.conf.js` file.
35+
36+
The default grunt task checks everything.
1237

1338
## Release History
1439

15-
#### 0.0.1 - 22 Apr 2014
16-
First release
40+
#### 0.0.3 - 7 Dec 2014
41+
Webpack 1.4 and fix for modules using window.angular
1742

1843
#### 0.0.2 - 28 July 2014
1944
Working well enough to build the angular-seed project.
2045

46+
#### 0.0.1 - 22 Apr 2014
47+
First release
48+
2149

2250
## License
2351
Copyright (c) 2014 Paul Thomas. Licensed under the MIT license.

lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ AngularPlugin.prototype = {
5656
apply: function(compiler){
5757
bindCallbackMethod(compiler, "compilation",
5858
this, this.addDependencyFactories);
59+
bindCallbackMethod(compiler.parser, "expression window.angular",
60+
this, this.addAngularVariable);
5961
bindCallbackMethod(compiler.parser, "expression angular",
6062
this, this.addAngularVariable);
6163
bindCallbackMethod(compiler.parser, "call angular.module",
File renamed without changes.

tasks/ngroute.stubjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
(function(window, angular, undefined) {
3+
// stub of angular-route.js
4+
})(window, window.angular);

tasks/webpack-scenario.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ module.exports = function(grunt){
5454
resolve: {
5555
root: path.resolve(confFile, '..', 'in'),
5656
alias: {
57-
angular: path.resolve(__dirname, 'stubng.js')
57+
angular: path.resolve(__dirname, 'ng.stubjs'),
58+
ngRoute: path.resolve(__dirname, 'ngroute.stubjs')
5859
}
5960
},
6061
}, config);

test/scenarios/alias-namespace/out/bundle.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ function(module, exports, __webpack_require__) {
1717
}.call(exports, __webpack_require__(3)))
1818
},
1919
function(module, exports, __webpack_require__) {
20+
(function(angular) {
2021
module.exports = window.angular
22+
}.call(exports, __webpack_require__(3)))
2123
}
2224
])
2325

test/scenarios/basic-module-dependency/out/bundle.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ function(module, exports, __webpack_require__) {
1515
}.call(exports, __webpack_require__(2)))
1616
},
1717
function(module, exports, __webpack_require__) {
18+
(function(angular) {
1819
// stub
1920
module.exports = window.angular
21+
}.call(exports, __webpack_require__(2)))
2022
}
2123
])

test/scenarios/basic-module/karma.conf.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,9 @@ module.exports = function(config) {
2626
resolve: {
2727
root: path.resolve(__dirname, 'in'),
2828
alias: {
29-
angular$: '../../../vendor/angular/angular.js'
29+
angular$: path.resolve(__dirname, '../../vendor/angular/angular.js')
3030
}
3131
},
32-
module: {
33-
noParse: /angular\.js$/,
34-
loaders: [{
35-
test: /angular\.js$/,
36-
loader: 'exports?window.angular'
37-
}]
38-
},
3932
plugins: [new AngularPlugin()]
4033
}
4134
});

test/scenarios/basic-module/out/bundle.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
(module.exports['main'] = angular.module('main', []));
66
}.call(exports, __webpack_require__(1)))
77
},
8-
function(module, exports, require) {
8+
function(module, exports, __webpack_require__) {
9+
(function(angular) {
910
// angular.js stub
1011
module.exports = window.angular
12+
}.call(exports, __webpack_require__(1)))
1113
}
1214
])

test/scenarios/dots-for-path-separator/out/bundle.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ function(module, exports, __webpack_require__) {
1313
}.call(exports, __webpack_require__(2)))
1414
},
1515
function(module, exports, __webpack_require__) {
16+
(function(angular) {
1617
// stub
1718
module.exports = window.angular
19+
}.call(exports, __webpack_require__(2)))
1820
}
1921
])
2022

0 commit comments

Comments
 (0)