grunt-amd-commonjs-wrapper
Convert a normal amd module to the simplified commonjs style amd module
What problem does this solve?
Specifying all the dependencies in an array, then receiving them in a callback makes it very difficult for a linter to detect unused dependencies. This in turn makes it hard to detect if files aren't being built into any requirejs build files.
;
When to use?
This is the opposite of most grunt tasks that you'd use as part of your build, in that it (hopefully) makes your code more readable and easy to lint. This means that you're only likely to use it a single time to convert the style of a huge project.
In addition, some people prefer writing their modules in the commonjs style (especially if you want to run your code in node as well). Once you've used this task to convert your modules, you could even just strip off the outer define call and re-add it at build time with something like grunt-amd-wrap.
Examples
;
becomes
;
supports variable-less dependencies
;
becomes
;
supports named modules
;
becomes
;
supports 'use strict'
;
becomes
;
leaves commonjs wrapper modules alone
;
remains
;
Whitespace Warning
There is an attempt to match the indentation of the rest of the file, but its far from perfect. Might upset your linter.
Relative Path Warning
If you're using paths not declared in your requirejs config file, then this will probably break all your paths. This is due to the commonjs style require statements using relative paths, rather than making all paths relative to your requirejs config baseUrl
setting.