Git Product home page Git Product logo

urequire's Introduction

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 ([email protected])

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.

urequire's People

Contributors

anodynos avatar englercj avatar vendethiel avatar

Watchers

pierre lepers avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.