Skip to content

Commit d3bee6e

Browse files
committed
Merge branch 'master' of github.com:gfranko/amdclean into dev
* 'master' of github.com:gfranko/amdclean: Promote the onModuleBundleComplete hook in README Added note to CJS wrapper support Added Link To The Getting Started Video
2 parents ca9fd9e + fad7999 commit d3bee6e

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

README.md

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ A build tool that converts AMD code to standard JavaScript.
77

88
`npm install amdclean --save-dev`
99

10+
[Getting Started Video](http://www.youtube.com/watch?v=wbEloOLU3wM)
11+
1012

1113
## Use Case
1214

13-
**Single file** client-side JavaScript libraries or applications that want to use AMD to structure and build their code, but don't want an AMD footprint.
15+
**Single file** client-side JavaScript libraries or web apps that want to use AMD to structure and build their code, but don't want an AMD footprint.
1416

1517

1618
## Used By
@@ -31,7 +33,7 @@ Many developers like to use the AMD API to write modular JavaScript, but do not
3133
By incorporating amdclean.js into the build process, there is no need for Require or Almond.
3234

3335
Since AMDclean rewrites your source code into standard JavaScript, it is a great
34-
fit for JavaScript library authors who want a tiny download in one file after using the
36+
fit for JavaScript library/web app authors who want a tiny download in one file after using the
3537
[RequireJS Optimizer](http://requirejs.org/docs/optimization.html).
3638

3739

@@ -48,7 +50,7 @@ It is best used for libraries or apps that use AMD and optimize all the modules
4850

4951
* [Shimmed modules](http://requirejs.org/docs/api.html#config-shim)
5052

51-
* [Simplified CJS wrapper](https://github.com/jrburke/requirejs/wiki/Differences-between-the-simplified-CommonJS-wrapper-and-standard-AMD-define#wiki-cjs)
53+
* [Simplified CJS wrapper](https://github.com/jrburke/requirejs/wiki/Differences-between-the-simplified-CommonJS-wrapper-and-standard-AMD-define#wiki-cjs) (requires the `globalObject` option to be set to `true`)
5254

5355
* Exporting global modules to the global `window` object
5456

@@ -78,7 +80,7 @@ There are a few different ways that amdclean can be used including:
7880

7981
* `npm install amdclean --save-dev`
8082

81-
* Make sure that each of your AMD modules have a module ID `path` alias name
83+
* Make sure that each of your AMD modules have a module ID `path` alias name (this is not required, but a good idea)
8284

8385
```javascript
8486
paths: {
@@ -92,24 +94,15 @@ paths: {
9294
}
9395
```
9496

95-
* If you are **not** shimming any libraries, add an `onBuildWrite` config property to your RequireJS build configuration file. Like this:
96-
97-
```javascript
98-
onBuildWrite: function (moduleName, path, contents) {
99-
return module.require('amdclean').clean(contents);
100-
}
101-
```
102-
103-
* If you **are** shimming any libraries, add an `onModuleBundleComplete` config property to your RequireJS build configuration file instead. Like this:
97+
* Add an `onModuleBundleComplete` config property to your RequireJS build configuration file instead. Like this:
10498

10599
```javascript
106100
onModuleBundleComplete: function (data) {
107-
var fs = require('fs'),
108-
amdclean = require('amdclean'),
101+
var fs = module.require('fs'),
102+
amdclean = module.require('amdclean'),
109103
outputFile = data.path;
110104
fs.writeFileSync(outputFile, amdclean.clean({
111-
'code': fs.readFileSync(outputFile),
112-
'globalObject': true
105+
'filePath': outputFile
113106
}));
114107
}
115108
```
@@ -133,8 +126,13 @@ module.exports = function(grunt) {
133126
mainConfigFile: 'src/js/app/config/config.js',
134127
include: ['first'],
135128
out: 'src/js/app/exampleLib.js',
136-
onBuildWrite: function( name, path, contents ) {
137-
return require('amdclean').clean(contents);
129+
onModuleBundleComplete: function (data) {
130+
var fs = require('fs'),
131+
amdclean = require('amdclean'),
132+
outputFile = data.path;
133+
fs.writeFileSync(outputFile, amdclean.clean({
134+
'filePath': outputFile
135+
}));
138136
}
139137
}
140138
}
@@ -153,14 +151,14 @@ module.exports = function(grunt) {
153151
* Require the module
154152

155153
```javascript
156-
var cleanAMD = require('amdclean');
154+
var amdclean = require('amdclean');
157155
```
158156

159157
* Call the clean method
160158

161159
```javascript
162160
var code = 'define("exampleModule", function() {});'
163-
var cleanedCode = cleanAMD.clean(code);
161+
var cleanedCode = amdclean.clean(code);
164162
```
165163

166164

@@ -457,6 +455,15 @@ __Why would I use AMDClean instead of Almond.js?__
457455

458456
- Although Almond is very small (~1k gzipped and minified), most JavaScript library authors do not want to have to include it in their library's source code. AMDClean allows you to use AMD without increasing your library's file size.
459457

458+
__Do I have to use the onModuleBundleComplete Require.js hook?__
459+
460+
- Nope, you may use the `onBuildWrite` Require.js hook instead. Like this:
461+
```javascript
462+
onBuildWrite: function (moduleName, path, contents) {
463+
return module.require('amdclean').clean(contents);
464+
}
465+
```
466+
460467
__AMDClean does not seem to be cleaning shimmed modules. What am I doing wrong?__
461468

462469
- Since Require.js does not expose the [shim](http://requirejs.org/docs/api.html#config-shim) functionality within the `onBuildWrite` config property, you must use the `onModuleBundleComplete` config property instead. Like this:
@@ -467,7 +474,7 @@ onModuleBundleComplete: function (data) {
467474
amdclean = require('amdclean'),
468475
outputFile = data.path;
469476
fs.writeFileSync(outputFile, amdclean.clean({
470-
'code': fs.readFileSync(outputFile),
477+
'filePath': outputFile,
471478
'globalObject': true
472479
}));
473480
}

0 commit comments

Comments
 (0)