coding

0.0.2 • Public • Published

coding

NPM version Build Status Dependency Status Code Climate Coverage Status

分析单个 Node 文件,解析其依赖,并将依赖及原文件合并成一个与 Node 无关的文件

因为它们编译出的文件很丑,而且添加了很多多余的代码。

  • coding 有什么特点?

缺点:

  • 需要遵守一定的格式来编写模块,也就是说开源的模块大部分都不适用,所以 coding 适合组织自己的代码,就像 jquery 一样
  • 每个模块即一个变量,会导入到全局之中,所以模块之间需要避免重名,但是支持设置 global,设置了的话所有变量会导入到 global

为什么还要用它:

  • 编译后的文件相对来说好看些
  • 当你有几个文件都需要引用同一个模块时,同时这几个文件并不只针对 Node,还需要针对 Browsers 也起作用
  • 可以组织自己的一个模块库,方便引用
  • 测试也方便,可以分小模块测试

安装

$ npm install --save coding

or

$ npm install --global coding

模块编写风格

  • requiremoduleexports 不能被重新定义,也不能创建它们的别名
  • 不支持 require('foo').bar 的写法
  • module.exports 应该写在最外层
  • require("xxx") 函数中只支持字面量的字符串,不能包含变量,也不能包含任何的表达式

使用

In javascript:

var coding = require('coding');
coding(filePath, options); // return compiled file content

When installed in global

coding [options] <file> // Use coding --help to see more helps

options

global

Type: string, Default: 'G'

模块变量的命名空间

rename

Type: function, Default: null

根据模块的文件路径重命名模块

函数的参数为模块对应的路径,如果函数返回的不为字符串,则使用系统默认的模块名称

addFilePathComment

Type: boolean, Default: true

在合并后的文件中添加文件路径的注释

saveMainExport

Type: boolean, Default: false

是否保留主文件中的 exports 声明

Contributing

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.

Reference

License

Copyright (c) 2015 Zhonglei Qiu. Licensed under the MIT license.

Package Sidebar

Install

npm i coding

Weekly Downloads

5

Version

0.0.2

License

MIT

Last publish

Collaborators

  • qiu8310