destealify is a browserify transform that allows free intermixing of StealJS modules with Node.js-style CommonJS modules.
It also supports webpack. See
examples/canjs-webpack
.
$ npm install destealify
browserify -t destealify main.js -o bundle.js
var browserify = require('browserify');
var fs = require('fs');
var b = browserify('main.js');
b.transform('destealify');
b.bundle().pipe(fs.createWriteStream('bundle.js'));
For packages that are written as StealJS modules, add a browserify
transform field to package.json
and browserify will apply the transform
to all modules in the package as it builds a bundle.
{
"name": "anchor",
"main": "main",
"browserify": {
"transform": "destealify"
}
}
Unfortunately, there's no obvious way to use browserify
directly with the
steal
version of CanJS. This is because browserify
does
not recursively transform dependencies, and expects them to do their own
transformation, or use the browserify
field -- which would then need further
configuration for the quirks of how the CanJS
repo works.
Instead, use webpack, which has a similar
featureset to browserify
. See examples/canjs-webpack
for details.
Most StealJS modules rely on absolute pathing. There are two ways around this:
node_modules/
to arrange your paths such that require()
works as expected for the paths in the steal module.stealconfig.js
file in a parent directory of your module and use the
map
and paths
options, which are handled by this transform, to map module
names as needed.For example, if you have a module that looks like:
steal("frob/this", function() {
});
destealify
will first translate that dependency to "frob/this/this.js"
,
following StealJS conventions.
If your this.js
library is located in
./bower_components/frobjs/this/index.js
, you can write a stealconfig.js in
your project's root that looks like:
steal.config({
map: {
"*": {
"frob/this/this.js": "thisjs"
}
},
paths: {
"thisjs": "bower_components/frobjs/this"
}
});
and everything will be taken care of for you.
destealify
is a public domain work, dedicated using
CC0 1.0. Feel free to do
whatever you want with it.