Replaces all the require and export statements with the actual js content from the required file. Compiles all your project's js file tree into one single perfect JavaScript file.
This guide will help you get started with cleanJS in no time. Using Clean JS is as easy as installing it, requiring and running it.
To use this module you will need NodeJs and/or npm installed on your development system. If you are using only node, then get a copy of the clean.js from the git repo and use it. Otherwise I assume that you have both Node and npm installed.
-
Get this CleanJS into project's npm dev devDependencies.
npm install --save-dev cleanjs
-
Require clean.js file into your gulp or grunt file
let CleanJS = require("cleanjs").Clean; new CleanJS("from/raw/entry.js","to/clean/single.js")
-
If you want to watch the files for changes go ahead
new CleanJS("from/raw/files.js","to/clean/single.js").watch()
-
Run as npm script
As of now this supports cleaning of js files directly so long there is require(files) to be converted to a single file js.
When using TypeScript give the link to your compiled entry.js file as the from argument to Perfect.
-
Clean out all require and export statements This is the sore aim of Clean JS, to give you a clear require-less and export-free code. Declare new Clean Object
new Clean(from : string, to :string, [options: Object ]);
from : string path to file.js from which all the require/export statement will be to be cleaned.
to : string path clean_file.js to which all clean js content will be written.
options: Object Plain JavaScript object specifying Clean Js preferences.
-
Clean out all source-maps.
This is preference based feature option, that lets you to clean out all the source maps produced by transpilers such as Typescript or Babel
removeSourceMapComment : boolean [false] Setting this option will tell CleanJS to remove source maps from the clean.js file.
-
Optimizes the js strict mode.
This allows you to optimize all "use strict" statements. Clean Js simply removes all and keeps only one major "use strict" to mark strict mode for the whole file.
optimizeStrictMode : boolean [true]
-
Optimizes strict mode by default and leaves source maps on through out development.
Clean( from : string, to : string, options : Object = { removeSourceMapComment: false, optimizeStrictMode: true } );
This gives a clean flat file with no extra code from external dependence tree modulation.
A successful Clean JS run gives you :-
- A clean single JavaScript file
- Less code unlike what you get when using build system /browserify
- Its straight forward and browser compatible js
- Improved code readability
- A simple new file while leaving your project intact
- Live Updates as project file/s change
- Satisfaction for getting rid of unnecessary require+ overhead from project project.
MIT