Transform require.js sugar syntax into the standard syntax.
Install via npm:
npm install unsweeten --save-dev
What it does
This module takes the require.js sugar syntax:
And converts it back into the standard syntax:
It will also work for dependencies that you are just loading but are not assigned to any variables, such as loading jQuery and a plugin:
For large projects using AMD, using
unsweeten will help you cut down a significant amount of loader code that just isn't necessary.
The best way to use this module is as a part of your
r.js build step. Using the
onBuildWrite function, you can apply extra transformations to your source code before it is minified. Below is an example configuration using gulp as a task runner:
var path =gulp =gutil =requirejs =unsweeten = ;gulp;
Some files may fail this transform. In the test directory are examples of code that will be transformed; notably absent are those files that have more than one
define call in them. When using this library on your own code you will most likely find that all of your development files have a single call to
define, as in my case. However, some vendor code may package up several of these calls into a single file. For this reason it is recommended to only use
unsweeten on your own code. Bear in mind that any file not run through this transform will continue to work as normal.
If you find an example of breakage using
unsweeten then please open an issue with the source code, output, and the expected output. If you can, a pull request is even better!
Pull requests are welcome. If you add functionality, then please add unit tests to cover it.
MIT © Ben Briggs