amdee
Converting CommonJS modules into AMD format
Last updated 7 years ago by yc .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install amdee 
SYNC missed versions from official npm registry.

Amdee

Overview

Amdee is a command-line tool for converting Node style packages into client-side scripts that cooperates with (requireJS)[http://www.requirejs.org].

The difference between Amdee and other systems like Browserify is that Amdee does not compile everything into a single script; it compiles only the files within the current node module into a single script, and expects requireJS to serve the external modules.

Amdee also provides many (but not all) core modules from Node for the client-side as well.

Amdee will convert a script, along with its relative dependencies within a package, into a single javascript file. All of the relative dependencies will be resolved to pure javascript variable, i.e.,

// main
var Foo = require('./foo');

will be compiled into something equivalent to the following

// foo_module

var foo_module = (function () { /* foo module definition */ })();

// main_module
var main_module = (function() {
  var Foo = foo_module; // require is parsed out from above
}); 

External modules will be left along and loaded as separate scripts via AMD mechanism. For exmaple:

// require jQuery
var $ = require('jquery'); // this is an external module.

Will be compiled as following

define(['jquery'], function(require, exports, module) {

    var $ = require('jquery');
}

And then you can setup the shim for requireJS as following:

require.config({
    "path": {
        "jquery": "http://..."
    }, 
    "shim": {
        "jquery": {
            "deps": [],
            "exports": "jQuery"
        }
    }
}); 

The config object for requireJS can be passed into the requirejs attribute of the amdee.run function, which is further described below.

Installation

$ npm install -g amdee

Usage

On Command line:

$ amdee --source <module_file> --target <output_file>

In Node program (below is written in coffee-script with expressjs)

express = require 'express'
amdee = require 'amdee'
app = express()

app.configure ->
  # ...
  amdee.run
    source: './client/main.coffee'
    target: './public/js/main.js'
    watch: true
    requirejs: # add requireJS's config here; will be written to main.js
      paths:
        jquery: 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min'
        'jquery.livequery': 'https://raw.github.com/brandonaaron/livequery/master/jquery.livequery'
        'jquery.address': 'https://raw.github.com/bzlib/jquery-address/master/src/jquery.address'
      shim:
        jquery:
          deps: []
          exports: 'jQuery'
        'jquery.livequery': ['jquery']
        'jquery.address': ['jquery']

The watch: true setting will ensure that if main.coffee & its relative dependencies are changed, main.js will be recompiled.

Ensure your main.coffee to include the needed dependencies the usual way.

$ = require 'jquery'
require 'jquery.address' # plugin does not return object
require 'jquery.livequery'

# add relative dependencies within the module

# ... your code ...

Any relative dependencies will be resolved into the same file, whereas the external dependencies will be loaded as separate scripts.

License

Amdee is released under MIT License.

Node Core Modules

  • Buffer - not available in browser
  • child_process - not available
  • cluster - not available in browser
  • crypto - not available
  • dns - not available
  • domain - not available
  • EventEmitter - available
  • fs - not available
  • globals
    • process - might not make sense
    • console - certainly needed
    • require - yes definitely needed
    • __filename
    • __dirname
    • module
    • exports
    • setTimeout
    • clearTimeout
    • setInterval
    • clearInterval
  • http - not sure if make sense, but partial request & response do
  • https - same thing
  • net - same thing
  • os - might not make sense either.
  • path - some of the capabilities make sense; but not sure all of it...
  • process - not sure...
  • punycode - don't even know what this does...
  • querstring - available
  • readline - not available
  • console - yes
  • stream - not available
  • string_decoder - not available
  • ssl - not available
  • udp - not available
  • url - yes
  • util - yes
  • vm - not avialable
  • zlib - not available

Current Tags

  • 0.5.5                                ...           latest (7 years ago)

7 Versions

  • 0.5.5                                ...           7 years ago
  • 0.5.4                                ...           7 years ago
  • 0.5.3                                ...           7 years ago
  • 0.5.2                                ...           7 years ago
  • 0.5.1                                ...           7 years ago
  • 0.5.0                                ...           7 years ago
  • 0.3.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (8)
Dev Dependencies (2)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |