R. js is part of RequireJS (optimizer ). It depends on UglifyJS, while UglifyJS is based on nodejs. Most of the time, r. js is combined and compressed with the modular (AMD) Writing Method. If your code does not use AMD, you can use it for compression. This article discusses how to compress the js file of the entire project without using AMD to organize code.
Assume that all the js files in the project are in the scripts directory.
The project contains three directories: css, html, and scripts, which correspond to css, html, and js files respectively. The downloaded r. js file is placed in parallel with myapp.
The JS file behind the scripts-builddirectory is structured in the same way as scripts, but a build.txt file is generated.
The build. js file needs to be configured by ourselves. r. js will find the compressed directory and the compressed directory. Probably as follows:
({
AppDir: "scripts ",
BaseUrl: "scripts ",
Dir: "scripts-build "})
The following are my tested projects (before compression)
As you can see, scripts-build is currently empty. Okay, start compressing.
1. Run cmd to go to the command line console. My project is on e:/work/myapp.
2. cd to the current project (enter the E drive, cd work/myapp)
3. Execute the command: node r. js-o build. js Effect
At this time, the computation was successful. Now we can see the scripts-builddirectory, And the scriptsstructure. We also have an additional build.txt.
From Snandy