distify
v0.0.1
Published
AST-aware module packager
Downloads
4
Maintainers
Readme
distify
Experimental browserify-based (mostly backwards-compatible) AST-aware module packager.
Idea
Architecture
Browserify transforms exist in two categories:
nonjs-to-js transforms (henceforth "converters"). * The source cannot be expressed in terms of an esprima-compatible AST because they're not js. * e.g.: handlebars/underscore templates compilers, coffeeify, jadeify, etc.
js-to-js transforms (not converters, henceforth "legacy transforms"). * The source can be expressed in terms of an esprima AST because they're js. * These most often do use an AST as intermediate step, but it's not shared. * babelify, brfs (inlines
fs.readFileSync()
calls), aliasify (remapsrequire
calls), envify (inlinesprocess.env
values), deAMDify, etc.
Internally, browserify has three legacy transforms:
- detective. Collects require calls.
- insert-module-globals. Wraps modules in an IIFE with references to
__filename
,__dirname
,process
andBuffer
- if needed. - syntax-error. Syntax checks files – uses acorn's own errors to present helpful messages with line numbers.
Converters are exogenous inputs into the build pipeline. However, Legacy transforms are AST transformations that can benefit from skipping the AST-building step.
+ nonjs-to-js: If Acorn can't read it, these turn it
| into something that it can. Includes the above mentioned, plus:
| * Turning `.json` files into `module.exports=JSON_CONTENT`.
| * BOM and shebang stripping.
|
| : 1. acorn
| : 2. babel transforms
| : 3. babel code gen
| :
v !~~~~~~~~~~~~~~~~!
converters -> JS -> ! AST -> JS+ ! -> legacy transforms -> packaging
!________________! ^
^ |
| * bundle splitting,
| * source maps, etc.
|
|
* babel & it's ES6/7 transforms
* user defined transforms
* internal transforms rewritten as babel plugins
* other transforms like: bundle-collapser, aliasify