包详细信息

commonjs-justhere

yunxu10195BSD31.0.1

CommonJS browser bundler with aliasing, extensibility, and source maps from the minified JS bundle

CommonJS, CommonJS Everywhere, CommonJS Justhere, browser

自述文件

CommonJS Justhere

更新了原 CommonJS Everywhere 中的一些陈旧的依赖项,添加了对typescript的支持。English Version

CommonJS Everywhere

CommonJS(节点模块)浏览器绑定器,具有从缩小的JS绑定到原始源的源映射、浏览器重写的别名以及任意编译到JS语言支持的扩展性。

安装

npm install -g commonjs-justhere

使用

命令行

$ bin/cjsify --help

  用法: cjsify OPT* path/to/entry-file.ext OPT*

  -a, --alias ALIAS:TO      将ALIAS标识的文件的要求替换为`TO`
  -h, --handler EXT:MODULE  使用扩展名EXT和MODULE模块处理文件
  -m, --minify              压缩输出
  -o, --output FILE         输出到FILE而不是stdout
  -r, --root DIR            相对路径是相对于DIR的;默认值:cwd
  -s, --source-map FILE     将源映射输出到FILE
  -v, --verbose             输出详细日志
  -w, --watch               监视输入文件/依赖项的更改并重新生成捆绑包
  -x, --export NAME         指定输出名为NAME
  --deps                    仅列出依赖项而不绑定
  --help                    显示帮助信息并退出
  --ignore-missing          当依赖项解析失败时继续
  --inline-source-map       将sourcemap作为数据URI包含在生成的包中
  --inline-sources          在生成的sourcemap中包含源内容;默认值:on
  --node                    包括process对象;模拟node环境;默认值:on
  --version                 显示版本号并退出

注意: 使用-作为条目文件接受javascript而不是stdin.

注意: 要禁用某个选项,请在其前面加上 no- ,例如: --no-node

示例:

一般用法

cjsify src/entry-file.js --export MyLibrary --source-map my-library.js.map >my-library.js

监视条目文件及其依赖项,以及新添加的依赖项。请注意,只有需要重建的文件在其依赖项时才被访问。这是一种比简单地重建一切更有效的方法。

cjsify -wo my-library.js -x MyLibrary src/entry-file.js

使用特定于浏览器的版本/lib/node compatible.js(记住使用“根”相对路径作为别名)。空别名目标用于在需要源模块时将错误延迟到运行时(在本例中为fs)。

cjsify -a /lib/node-compatible.js:/lib/browser-compatible.js -a fs: -x MyLibrary lib/entry-file.js

模块接口

cjsify(entryPoint, root, options) → Spidermonkey AST

绑定给定文件及其依赖项;返回绑定的spidermonkey AST表示。通过'escodegen'运行ast以生成js代码。

  • entrypoint是一个相对于process.cwd()的文件,该文件将是标记为包含在包中的初始模块以及导出的模块
  • root相对于哪个路径;默认为'process.cwd()`.
  • options是一个可选对象(默认为‘’’),具有以下零个或多个属性
    • export:要添加到全局作用域的变量名;从'entrypoint'模块分配导出的对象。可以提供任何有效的[左侧表达式](http://es5.github.com/x11.2)。
    • aliases:其键和值为“根”根路径(/src/file.js)的对象,表示将替换的值需要解析为关联键
    • handlers:一个对象,其键是文件扩展名(.roy),其值是从文件内容到spidermonkey格式js ast(如esprima生成的格式)或js字符串的函数。默认情况下包括coffeescript和json的处理程序。如果没有为文件扩展名定义处理程序,则假定它是javascript。
    • node:一个错误的值会导致绑定阶段忽略模拟节点环境的'process'存根。
    • verbose: 将其他操作信息记录到stderr
    • ignoreMissing: 忽略依赖缺失的问题

示例

命令行用法

假设我们有以下目录树:

* todos/
  * components/
    * users/
      - model.coffee
    * todos/
      - index.coffee
  * public/
    * javascripts/

运行以下命令将index.coffee及其依赖项导出为app.todos

cjsify -o public/javascripts/app.js -x App.Todos -r components components/todos/index.coffee

由于上面的命令将components指定为unqualified requires的根目录,因此我们可以使用require 'users/model'来要求'components/users/model.coffee'。输出文件将是'public/javascripts/app.js`。

Node 模块示例

jsAst = (require 'commonjs-justhere').cjsify 'src/entry-file.coffee', __dirname,
  export: 'MyLibrary'
  aliases:
    '/src/module-that-only-works-in-node.coffee': '/src/module-that-does-the-same-thing-in-the-browser.coffee'
  handlers:
    '.roy': (roySource, filename) ->
      # Roy编译器现在输出JS代码,所以我们用esprima分析它。
      (require 'esprima').parse (require 'roy').compile roySource, {filename}

{map, code} = (require 'escodegen').generate jsAst,
  sourceMapRoot: __dirname
  sourceMapWithCode: true
  sourceMap: true

简单输出

更新日志

v0.9.7 (2014-02-15)

  • 6e7c8f7c: fixes #92: allow handlers given via CLI to be resolved relative to CWD
  • 13a9addb: fixes #91: add amd support through --amd flag
  • bd0a55fd: update dependencies

v0.9.6 (2014-02-07)

  • 2df23977: Version 0.9.6
  • 42e5c876: rebuild using new CSR version
  • 05019b93: Merge pull request #90 from Constellation/update-es-tools
  • 3722ced1: Update esmangle and escodegen

v0.9.5 (2014-01-21)

  • 4e9a9e29: Version 0.9.5
  • ad84e452: update to CoffeeScriptRedux version 2.0.0-beta8
  • b3ae6ebd: fixes #87: resolve core modules consistently
  • 9f41e754: update some dependency specifications

v0.9.4 (2013-09-15)

  • c89df52b: Version 0.9.4
  • 7d969b72: fixes #81: improve documentation for aliasing
  • 58fc9a7c: update dependency versions
  • 65819399: remove some unnecessary parentheses
  • 0f77e4d2: fixes #78: fix path canonicalisation and some erroneous tests
  • 1e0ef697: rebuild with new CoffeeScript compiler version

v0.9.3 (2013-08-30)

  • 046da017: Version 0.9.3
  • 0343e4f4: update coffee-script-redux to version 2.0.0-beta7
  • f9201f47: move CHANGELOG generation from ruby gem to shell script

v0.9.2 (2013-07-20)

  • 584005c2: Version 0.9.2
  • a788c6b1: loosen up querystring requirement
  • 68470d1a: fixes #73: support constants core module using constants-browserify
  • 6c3cc71f: remove erroneous .js from underscore-prefixed node core module listings
  • afae2e7c: protect against changes of main module in dependencies
  • c9164cb5: add more compatible punycode implementation

v0.9.1 (2013-07-17)

  • 048f829c: Version 0.9.1
  • 268477ad: update to isaacs/nopt@2.1.2 to support - as stdin representation again

v0.9.0 (2013-07-15)

  • cd51af47: Version 0.9.0
  • 30db2bc2: upgrade node to v0.10.13
  • 81156f3b: upgrade CoffeeScriptRedux to version 2.0.0-beta6

v0.8.1 (2013-07-15)

  • 84e370bf: Version 0.8.1
  • ab4f403e: a bit of a restructuring of the dependency resolution functions
  • 9efc3fc9: add some aliasing tests
  • 3b67b970: rebuild parent commit
  • bb05a791: use new escodegen.FORMAT_MINIFY constant
  • 0b787588: link to isaacs/nopt#20 instead of b8101f920e7bdcf758f97ba9b17c7d0422d67992
  • a5dcc310: more succinct option specification
  • 92315a5f: switch from michaelficarra/Jedediah to isaacs/nopt

v0.8.0 (2013-06-27)

  • 8f61bf5b: Version 0.8.0
  • 582fa43b: Merge branch 'new-sourceMappingURL-pragma'
  • 0e0f2546: fixes #64: add CLI option for extension handlers
  • d6dad8c7: fixes #34: allow handlers to return JS strings
  • 666b45e2: fixes #71: allow empty alias targets
  • 83765f72: change sourceMappingURL pragma to new //# format

v0.7.3 (2013-06-22)

  • fab9d809: Version 0.7.3
  • 86629c13: add newline to end of package.json in release tasks
  • 9c798593: fixes #28: add CLI option to specify aliases
  • 95f29212: nicer handling of !=1 entry point error

v0.7.2 (2013-06-03)

  • 1633449a: Version 0.7.2
  • c94ec2f2: fixes #69: normalise windows/unix paths during canonicalisation
  • 84a590af: fixes #66: add --inline-source-map option to include map as data URI
  • 69f68622: fixes #33: add --inline-sources flag to include source content in map
  • fd354a6b: recompile with CoffeeScriptRedux 2.0.0-beta5
  • b1c15f4b: clean up lib/index.js; moved to lib/module.js

v0.7.1 (2013-05-14)

  • 2291ffa7: Version 0.7.1
  • cfb65476: release-X targets now update CHANGELOG
  • b4d7d12d: release-{patch,minor,major} make targets now update changelog
  • a0d69620: fixes #62: improve logging in watch mode
  • a40025fb: Merge pull request #61 from krisnye/master
  • 09a1cf44: Making curr.ino? check platform specific to win32
  • ae64c225: fix CoffeeScriptRedux version to 2.0.0-beta5
  • f864c043: Fix -w option to work on windows
  • 82562ea4: some minor documentation updates regarding watch and source-map options
  • ebd855f2: fixes #56: add a changelog
  • 1ff7b178: Merge pull request #54 from Nami-Doc/master
  • a317399f: silence makefile

v0.7.0 (2013-04-27)

  • 13edd235: Version 0.7.0
  • 84923100: remove leftover (sync)s in test suite descriptors
  • 77d40f34: move test/_setup.coffee to test-setup.coffee
  • 8874a177: fixes #53: modularisation
  • 91735b73: fixes #49: de-duplicate src/index.coffee by removing async interface
  • 406b8271: add CLI --version flag; I can't believe I didn't already add this
  • 733ff9ca: change --source-map-file option to --source-map; add -s alias
  • 4c965b56: fixes #50: sourceMappingURL should be relative to output file if given

v0.6.3 (2013-04-25)

  • 5464c5e8: Version 0.6.3
  • a35ed96a: fixes #48: clean up output from syntax errors thrown by esprima

v0.6.2 (2013-04-21)

  • 23761b57: Version 0.6.2
  • 1425b3c3: fixes #44: CLI no longer stops building when errors occur while watching
  • bf8f3f7e: fixes #45: implement cache option for traverseDependencies
  • 9917fc61: only include comments in generated output when not minifying
  • cf602393: add leading "generated by" comment; refs substack/node-browserify#380
  • 03921196: slightly cleaner process.nextTick test
  • 12b064df: add tests for process.nextTick
  • fcf9c1a9: process.nextTick uses setImmediate if available

v0.6.1 (2013-04-05)

  • 55e884c6: Version 0.6.1
  • 61a16a34: re-ignore node submodule

v0.6.0 (2013-04-05)

  • a4314951: Version 0.6.0
  • 0a515514: fixes #41: add --deps flag to CLI; lists dependencies without bundling
  • 210ae5f7: fix error messages for unported node core modules
  • 823c19e8: fixes #39: core module symlinks are not packaged properly by npm
  • ac3b58d8: fixes #36: allow process stub to be omitted
  • c95f10f4: update README demo for sync/async interface
  • 80f4af68: add safety checks around release build targets

v0.5.1 (2013-03-31)

  • d1a7ddb8: Version 0.5.1
  • 7913adb2: use . as sourceMapRoot when source map is generated in root directory
  • f6b2efd6: use relative paths for sourceMapRoot value in source maps; closes #37
  • f92ca08f: fixes #32: support accepting entry point over stdin
  • bebf9cc4: .travis.yml indentation
  • 99f72145: Merge pull request #35 from ghempton/events
  • e5d2b099: support for 'events' core module
  • 55192c9c: add watch (and terse flags) example to readme

v0.5.0 (2013-03-21)

  • 19c5af84: Version 0.5.0
  • 338dbd3e: document --watch
  • 2a0562e7: update travis specification to use strings for versions
  • 41eadc44: switch --watch from fs.watch to more appropriate fs.watchFile
  • 7ad8239e: fixes #31: add --watch flag to CLI for continuous builds on dep changes
  • 71bdfb2c: move entryPoint canonicalisation into bundling function
  • 8ef53183: undefined core modules now produce an error by default
  • ced85bc2: index processed hash by filename instead of canonical name; refs #31
  • fc51af83: add core dependency resolution test
  • 27f4d49a: succinctly specify test files while still hopefully keeping Travis happy
  • 476f0b3b: add "bundle" to package.json keywords

v0.4.0 (2013-03-20)

  • c787513a: Version 0.4.0
  • cbc018e4: document async bundling interface
  • 4f1f97cc: switch worklist entries from ordered pairs to objects
  • b1e95f5e: implement traverseDependencies
  • 6ce6db16: move "TODO: async" to traverseDependencies, where it belongs for now
  • 2a52714e: start Travis testing against node 0.10.x
  • 3b9fe5b2: one last attempt to get Travis running tests properly
  • 67ba7757: glob tests so (hopefully) Travis once again passes
  • e5dec44c: allow core libraries in bundle to appear with the core library name
  • c3d2b4c0: test naming/organisation
  • 15e05b11: update joyent/node submodule to v0.10.0
  • cccb8c3e: add some tests for node core libraries
  • 5a797eb7: DRY the tests a bit
  • 4bc7f0ea: add tests for process.argv and process.env
  • 247b0e39: implement process.chdir; test process.cwd and process.chdir
  • f226c98f: add process.version support
  • e230ddb6: add basic process tests
  • 5e5b4b05: add async tests for the last 2 commits
  • 51796592: support module.children
  • d90a6b3d: support module.parent; based on substack/node-browserify#323
  • 70ca7a79: round out tests for traverseDependenciesSync
  • 2893951d: a few more tests for #31; more to come
  • 1da8d4b4: fixes #31: split out and expose dependency traversal
  • 18800f4e: add async bundling tests
  • 8f6e98aa: start adding async interface; ref #17
  • 1f9be258: PHONY the appropriate make targets
  • 5006cd63: add release tasks
  • f476442a: remove accidental mutation of given options object

v0.3.5 (2013-03-08)

  • 25a9c72f: Version 0.3.5
  • 5b3f660d: JS => Node Module
  • 07e5c8f1: fixes #19: add ignoreMissing option
  • e7959ec1: fixes #29: export helpers iff we're in a testing environment
  • 3e380ff1: add 0.9.x to supported engines since we're running it through travis
  • 56fa6ff6: Merge pull request #27 from poulejapon/patch-1
  • ac2ca854: add module caching test
  • 3d45d7a9: add circular dependency test
  • 82ccb726: Fixed travis' node versions.
  • c4f893b5: fixes #24: use a single process instance
  • 0232a453: fixes #6: add basic bundling tests; obviously still need to expand them
  • 325f1df9: small test cleanup
  • b6784bdb: start generating fixtures for tests; starts progress on #6
  • 2353fffc: Merge pull request #26 from poulejapon/852c83d6eb026fe3be70c0e706d3ef91e7178d08
  • 852c83d6: Added travis settings.

v0.3.4 (2013-03-03)

  • 33bc2330: Version 0.3.4
  • 70476f1d: fixes #23: support circular dependencies

v0.3.3 (2013-03-03)

  • bafdec55: Version 0.3.3
  • c601a3e0: fixes #21 for real: small tweaks to .npmignore

v0.3.2 (2013-03-03)

  • 68821870: Version 0.3.2
  • 81f6c6b8: fixes #21: add .npmignore to reduce package size
  • 0623dbb2: switch to more familiar top-level IIFE style using simple parens

v0.3.1 (2013-03-02)

  • 9838cf29: Version 0.3.1
  • 1f06ea30: fixes #20: implement badRequireError
  • 472abd07: replace AST literals with esprima.parse + mutations
  • c2e65bd5: fixes #16: modularise and clean up src/index.coffee
  • b01eb1cb: fixes #18: add a verbose option and a --verbose flag
  • 62045c9d: switch more git submodules to npm packages and change associated links
  • 466dccf8: fixes #5: use browserify-http as a dependency instead of a submodule
  • 93f3c9af: fill in package.json
  • 6a3cd299: add BSD license
  • 64caf5e2: delete unnecessary gitignore file; put these in your global gitignore

v0.3.0 (2013-02-28)

  • 83b91485: Version 0.3.0
  • 09624819: Merge pull request #14 from benjreinhart/master
  • f7e54478: fixes #15: require the entry point module even if not exported
  • e4006bab: Some dumbass mispelled cjsify
  • c77dbf6d: Merge pull request #10 from benjreinhart/nested-exports
  • 79e45653: Support nested objects
  • 77802dce: Merge pull request #12 from Nami-Doc/patch-1
  • 584e31c2: document handler second argument
  • 7ce2f7c9: Merge pull request #8 from benjreinhart/master
  • 080bbd35: Fixing -r option
  • c4c16cef: Merge branch 'master' of github.com:michaelficarra/commonjs-everywhere
  • 0934714c: documentation cleanup
  • fd0d62c3: Version 0.2.0
  • f13ea232: use coffee-script-redux master to avoid a recently patched bug
  • da09579c: pass around extensions in order to properly support custom handlers
  • 4a7e57db: add some documentation to the README

v0.2.0 (2013-02-24)

  • f48bfa76: Version 0.2.0
  • b3891d66: use coffee-script-redux master to avoid a recently patched bug
  • 85fc3b2b: pass around extensions in order to properly support custom handlers
  • 0ece9d17: add querystring shim
  • 1a700c95: better errors for unfound modules
  • c05ed7c7: support requiring from required symlinks
  • 8c676d6c: use resolvePath for alias resolution to allow flexible specification

v0.1.1 (2013-02-23)

  • 2f5205e7: version 0.1.1
  • 916c8577: add crypto, http, and vm node core modules
  • d5d8f4d1: Merge branch 'master' of github.com:michaelficarra/commonjs-everywhere
  • 7ea6be07: Merge pull request #4 from benjreinhart/master
  • 3b28ac5e: Mutate entryPoint to be resolved path
  • b9428da4: process.cwd()
  • 075cc9b7: Compute correct path when given root option
  • 671d5fab: add symlinks to node core libraries that work as-is in the browser
  • c80f12b9: Merge pull request #2 from benjreinhart/master
  • d0aef9c2: Minimal Readme

v0.1.0 (2013-02-23)

  • 2644cda8: add source map support, fix minification, change interfaces, 0.1.0
  • bf6052a8: add --minify flag and integrate with esmangle
  • 9d4c2193: rename bin/build to bin/cjsify
  • 77240e10: add --help flag
  • 24f3a9cf: documentation note
  • ef3c0f2e: update jedediah dependency to 0.1.0
  • 33dc2ce5: fix repo URL
  • 89311ab3: Merge pull request #1 from EndangeredMassa/smassa/dependency-update
  • 516ab74b: added .gitignore
  • 7c9743b1: updated package.json with jedediah dependency
  • 29b13ea6: initial commit