分析单个 Node 文件,解析其依赖,并将依赖及原文件合并成一个与 Node 无关的文件
npm install coding分析单个 Node 文件,解析其依赖,并将依赖及原文件合并成一个与 Node 无关的文件
* 为什么不用 browserify 或 webmake?
> 因为它们编译出的文件很丑,而且添加了很多多余的代码。
* coding 有什么特点?
> __缺点:__
>
> * 需要遵守一定的格式来编写模块,也就是说开源的模块大部分都不适用,所以 coding 适合组织自己的代码,就像 jquery 一样
> * 每个模块即一个变量,会导入到全局之中,所以模块之间需要避免重名,但是支持设置 global,设置了的话所有变量会导入到 global 下
>
> __为什么还要用它:__
>
> * 编译后的文件相对来说好看些
> * 当你有几个文件都需要引用同一个模块时,同时这几个文件并不只针对 Node,还需要针对 Browsers 也起作用
> * 可以组织自己的一个模块库,方便引用
> * 测试也方便,可以分小模块测试
``bash`
$ npm install --save coding
or
`bash`
$ npm install --global coding
* require、module 和 exports 不能被重新定义,也不能创建它们的别名require('foo').bar
* 不支持 的写法module.exports
* 应该写在最外层require("xxx")
* 函数中只支持字面量的字符串,不能包含变量,也不能包含任何的表达式
In javascript:
`javascript`
var coding = require('coding');
coding(filePath, options); // return compiled file content
When installed in global
`bash`
coding [options]
Type: string, Default: 'G'
模块变量的命名空间
Type: function, Default: null
根据模块的文件路径重命名模块
函数的参数为模块对应的路径,如果函数返回的不为字符串,则使用系统默认的模块名称
Type: boolean, Default: true
在合并后的文件中添加文件路径的注释
Type: boolean, Default: false
是否保留主文件中的 exports` 声明
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using gulp.
* How browserify works
* ECMAScript Tooling Organization
* estraverse
* catharsis - A JavaScript parser for Google Closure Compiler and JSDoc type expressions.
* ast-query - Tentative to a simple JavaScript AST modification library
* ast-types - This module provides an efficient, modular, Esprima-compatible implementation of the abstract syntax tree type hierarchy pioneered by the Mozilla Parser API.
* ast-traverse - Simple but flexible AST traversal with pre and post visitors. Works in node and browsers.
Copyright (c) 2015 Zhonglei Qiu. Licensed under the MIT license.
[climate-url]: https://codeclimate.com/github/qiu8310/coding
[climate-image]: https://codeclimate.com/github/qiu8310/coding/badges/gpa.svg
[npm-url]: https://npmjs.org/package/coding
[npm-image]: https://badge.fury.io/js/coding.svg
[travis-url]: https://travis-ci.org/qiu8310/coding
[travis-image]: https://travis-ci.org/qiu8310/coding.svg?branch=master
[daviddm-url]: https://david-dm.org/qiu8310/coding.svg?theme=shields.io
[daviddm-image]: https://david-dm.org/qiu8310/coding
[coveralls-url]: https://coveralls.io/r/qiu8310/coding
[coveralls-image]: https://coveralls.io/repos/qiu8310/coding/badge.png