plepers / uRequire

Convert AMD & commonjs modules to UMD, AMD, commonjs or `combined.js` (rjs & almond) & run/test on nodejs, Web/AMD or Web/Script. Manipulate & inject module code & dependencies while building & more

Home Page:http://urequire.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

uRequire v0.6.10

Build Status Up to date Status

The JavaScript Universal Module & Resource Converter

Convert AMD & commonjs modules to commonjs, AMD, UMD or single .js and run/test on nodejs, Web/AMD or Web/Script.

All documentation is moved to the wiki and http://urequire.org

Support uRequire

  • @goto('http://github.com/anodynos/urequire').then -> @star() with your love :-)

  • Flattr donate button PayPayl donate button

Some Introduction

Why use modules like AMD or Common/JS ?

Write modular, maintainable & reusable code:

  • Clearly stated dependencies & imports.

  • Employ standards and trusted tools.

  • Have a dynamic code loading mechanism.

  • The damnation of one huge .js file or concatenation must end!

Are U still concatenating .js files ?

But javascript developers hate modules!

Many woes on Module formats & incombatibilities:

U need a bridge to enjoy the richness of modules.

require('more').than(this);

Why use uRequire ?

If U required it or defined it, uRequire will find it.

Simplest Module Authoring

define(['dep1','dep2'], function(dep1,dep2) {
  // do stuff with dep1, dep2
  return {my:'module'}
});

// or
var dep1 = require('dep1'),
    dep2 = require('dep2');
// do stuff with dep1, dep2
module.exports = {my: 'module'}

// or both, in a relaxed, non-weird way
define(['dep1','dep2'], function(dep1,dep2) {
  var dep3JSON = require('json!dep3AsJSON');
  // do stuff with dep1, dep2, dep3JSON
  return {my:'module'}
});

Exporting modules to window/global variables (like window._, window.$ etc), demystified and with no boilerplate.

Want noConflict(), baked in? Its a simple declaration away.

// file `uberscore.js` - export it to root (`window`) as `_B`
({ urequire: { rootExports: '_B', noConflict: true }});
module.exports = {...}

The same in a config is

dependencies: { exports: { root: { 'uberscore': '_B' }}}`

How about exporting to your bundle only?

// export/inject `_` in (all) bundle's modules
dependencies: { exports: { bundle: { 'lodash': '_' }}}

Want to replace deps with mocks or alternative versions ?

Inject, replace or even delete dependencies with a simple declaration or a callback:

// underscore is dead, long live _
dependencies: { replace: { lodash: 'underscore'}}

// with code
function(modyle){ modyle.replaceDeps('models/PersonModel', 'mock/models/PersonModelMock'); }

Manipulate Module code while building:

// delete matching code of code skeleton
function(m){ m.replaceCode('if (debug){}') }

// traverse matching nodes, replace or delete em
function(m){ m.replaceCode('console.log()', function(nodeAST){return nodeOrStringOrUndefined}) }

Perform any code manipulation - eg remove debug code, inject initializations etc

# unify / merge repeating statements
bundle: commonCode: 'var expect = chai.expect;'
function(m) { m.beforeBody = 'var l = new _B.Logger("Logger" + m.dstFilename);' }

A ResourceConverter for our .coco files (included along with coffeescript, LiveScript, iced-coffee-script)

[ '$coco', [ '**/*.co'], ((r)-> require('coco').compile r.converted), '.js']

A spartan Module builder & config

This 'uberscore' config (coffeescript) will:

# Config as a `Gruntfile.coffee` task
# Can be a .coffee, .js, .json, .yml & more
uberscore:
  path: 'source'
  dstPath: 'build'
  filez: ['**/*', (f)-> f isnt 'badfile']
  copy: [/./]
  runtimeInfo: ['!**/*', 'Logger.js']
  dependencies: exports:
    bundle: 'lodash':  '_'
    root: 'uberscore': '_B'
  resources: [
    ['+inject:VERSION', ['uberscore.js'],
     (module)-> module.beforeBody =
                  "var VERSION = '0.0.15';"]
  ]
  template: banner: "// uBerscore v0.0.15"
  optimize: 'uglify2'
  clean: true
  watch: true

Parent configs ? Lets derive!

The 'distribute' config will:

See more examples

Lets derive some children

distribute:
  derive: ['uberscore']
  filez: ['!', /useRegExpsAsFileSpecs/]
  template: 'combined'
  dstPath: 'build/uberscore-combined.js'
  optimize: uglify2: {more: uglify2: options}

Continue reading at http://urequire.org

License

The MIT License

Copyright (c) 2013 Agelos Pikoulas (agelos.pikoulas@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Convert AMD & commonjs modules to UMD, AMD, commonjs or `combined.js` (rjs & almond) & run/test on nodejs, Web/AMD or Web/Script. Manipulate & inject module code & dependencies while building & more

http://urequire.org

License:MIT License


Languages

Language:CoffeeScript 100.0%