Package Exports
- re-define
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (re-define) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
re-define
Let's re-define
something ... without any configuration ... just do the magic for me.
Easy way to convert AMD and CommonJS projects to one bundle wrapped in UMD
.
Why
- to get decent encapsulation, registering a bundle not a part
- to make project compatibile across node and web without effort
Features
- highly customizable: templates, transforms (like with browserify), discoverable folders
- now also resolving modules dependencies
- looking for dependencies in
node_modules
andbower_components
- resolving whole dependencies trees as well as single file
- resolving AMD !text plugin within
cjs
andamd
code - using
vinyl
, integration withgulp
should be easy - (WiP) detailed report, to get whole picture, display modules, dependencies and externals
Nice things
- when
re-define
meet external dep, automatically checks descriptor files, such asbower.json
andpackage.json, there is also a fallback to
node_modulesas well as
bower_componentswhen descriptor is missing or there is no
main` defined - when including an
UMD
file as a dep and yourdefine
module is anonymous,re-define
will add a name for you also check internal depenencies
Limitation
- does not resolve circular dependencies
module.export
overrideexports
when defined below exports- resolve only static
require
statements
Getting Started
Install the module: npm install -g re-define
###Usage
Usage: re-define [options]
Options:
'-t, --transform [libs]' , 'Custom transforms stream invoked for each module'
'-m, --main [filepath]' , 'Main file'
'-b, --base [dir]' , 'CWD'
'-d, --discoverable [dirs]' , 'Check in folders when encouter an external dep'
'-e, --external [json]' , 'Exact dep locations, when discoverable is not enough'
'-g, --globals [module#as]' , 'Global reference to external libs'
'-w, --wrapper [type]' , 'Wrapper type report, default: umd'
'-n, --name [module]' , 'Module name'
'-r, --returns [module]' , 'What module returns'
'-s, --skip [module]' , 'Exclude external module from result bundle'
'-e, --exclude-deps [deps]' , 'Exclude deps'
Example usage
check example folder and appropriate build files
Debbuging
To run re-define
in debug mode is fairly easy, just run re-define
with appropriate category like below
//all
DEBUG=re-define:*
//specific:
re-define:transform:*
re-define:converter
re-define:bin
###Config
{ cwd : '.'
, name : 'module_name'
, wrapper : 'umd'
, returns : ''
, excludeDepRef : ['\.css$', 'require', 'modules', 'exports']
, globals : [] //external module_name#global_ref
, external : {} //{"jquery": "location"} or {"..": "{path: "...", cwd: "..."}
, discoverable : ['node_modules', 'bower_component']
, descriptors : ['package.json', 'bower.json']
, plugins : [{extension: '.html', pattern : '^(text\/?)*!'}]
, escape : function (val) { return val.replace(/\.\/|\!|\.|\/|\\|-/g, '_') }
}
####Custom transform
var through = require('through2')
module.exports = function(config) {
//config instance
return through.obj(function(file, enc, next) {
/*
//inside of file you can find following properties
{
"cwd": "lib",
"base": "lib",
"path": "./lib/main.js",
"ext": ".js",
"type": "require",
"ast" : ...
"contents" : ...
"deps": [
{
"path": "jquery",
"require": "jquery"
}
...
]
*/
//your own spells
this.push(file)
next()
})
}