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
<script src='re-define.js' />
Let's re-define
something ... without any configuration ... just do the magic for me, yet another build tool.
Easy way to pack your application source files into one file(s) in order to build a bundle(s) you can use in <scipt>
tag. re-define
checks recursively require
calls and could be used either to AMD or CommonJS files, since all AMD modules are converted into CJS.
Check examples to get better picture.
Nice things
- require function allows to reference different
namespaces
- all modules are wrapped in cjs wrapper
function(exports, require, module, __filename, __dirname)
- ability to split bundles using
glob
, to extract common parts based on folder - when piping passing
vinyl
files (integration with gulp) - automatically loads configuration from file
re-define.json
- handling glob pattern as an input
- for external deps (outside the base folder or those which live in node_modules/bower_components) it checks descriptor files, such as
bower.json
orpackage.json
, if there is no descriptor it is trying to match file with requested dep name, check re-define-include-external to get more details re-define
make names for module appropriatelty to folder structure and expose it within given namespace which could be referenced further from any other different module, this is: assuming your module is placed in foldermy_awesome_component
all internal modules are presented asmy_awesome_component/**
. (check tests to get more info)
Why
- to provide better support for
amd
- to share code and expose more than one module within namespace and import from others
- to be able to handle all modern js build systems in one
- to generating templates tailored to your needs with all relevant information, i.e. external dependencies
TODO
- incremental builds
- generating
sourcemaps
- separate namespace for bundles when slicing
Limitation
- does not resolve circular dependencies
- resolve only static
require
statements
Getting Started
Install the module: npm install -g re-define
###Usage
re-define [file/files or glob pattern] -[options]
Options:
'-b, --base [dir]' , 'Base dir'
'-o, --output [dir or file]' , 'Output, when defined saving to appropriate files'
'-t, --transforms [libs]' , 'Attach transform streams'
'-e, --exclude-deps [deps]' , 'Ignore deps - ".css"'
'-m, --map-deps [deps]' , 'Remap dependency name (require call)'
'--namespace [a.b.c.d]' , 'Namespace for bundle'
'--imports [namespaces]' , 'Import namespaces'
'-g, --globals [json]' , 'Map externals to global - {jquery:this.jquery}'
'-n, --names [json]' , 'Register names for AMD/Global, i.e {amd:"sth",global:"sth.sth"}'
'-r, --returns [file/module]' , 'Return module, could be specified as file or resolved module'
'-w, --wrapper [type]' , 'Wrapper type umd'
'-p, --project-name [name]' , 'Project name, it becomes prefix for your internal modules name'
'--external [json]' , 'Include module from external location {lib:path}')
'--discoverable [dirs]' , 'External modules lib, such bower_components'
'--descriptors [files]' , 'Checking main file in external dep descriptor'
'--skip [module]' , 'Skip external module'
###Config
module.exports =
{ names : {amd: 'amd/name', global: 'global.name'}
, returns : ''
, globals : {} //external {module_name:global_ref}, e.g. {"jquery":"$"}
, project : '' //project name
//define cutting points for modules { glob_pattern: file }
, slice : {"**/**": "bundle.js"}
//could be a folder (in case of many files) or just file, when not defined print output to console
, output : ''
//base folder, all modules will be aligned to that
, base : '.'
//wrapper file
, wrapper : 'default'
//attach all bundled modules to namespace
, namespace: "your.namespace"
//exclude specific AMD dependencies
, excludeAMDModules : ['\.css$', 'require', 'modules', 'exports']
//regexp to detect an AMD plugins, first we need to remove the plugin prefix to get a path
, plugins : ['^(text\/?)*!']
//import namespaces, if you need to take some deps from globals like jquery, define it as ['window']
, imports: []
//remap require calls, helpful when some libs have different reference to the same module
, map: {}
//format for escodegen
, format: {
indent: { style: ' ', base: 2 },
space: ' ',
safeConcatenation:true
}
}
###How it works ####Imports
//create namespace for components
re-define lookup.js --namespace org.component
//import it to make it accessible for your code
re-define index.js --imports this.org.component --namespace org.site
To get more, check this example
####Custom transforms
####Compilation time Some results could be found here.
Debbuging
To run re-define
in debug mode, just run DEBUG=re-define:* re-define