0.1.0 • Published 11 years ago
koa-browserify v0.1.0
koa-browserify
middleware for koa.js that compile CommonJS modules
install
npm i koa-browserifyexample
var app = require('koa')(),
browserify = require('koa-browserify');
app.use(browserify({
root: './public', // root folder for js files
debug: true // show sorcemap
}));
app.use(browserify('./public')) // equivalent to {root: './public'}
app.listen(3000);options
rootroot folder for scriptsdebugenable soucemapsproductionenable production mode. In production soucemaps not working and code is minifiedtransformyou can transform original souce with this option. This options should be a function, that will be called with tr(file) and it should return a through-stream that takes the raw file contents and produces the transformed source.runtimeyou can add adition runtime sources by passing this option
this code will compile jsx files to js code
var browserify = require('koa-browserify'),
reactify = require('reactify');
app.use(browserify({
root: './public',
transform: reactify,
}));or
var browserify = require('koa-browserify'),
6to5ify = require('6to5ify');
app.use(browserify({
root: './public',
transform: 6to5ify,
runtime: require.resolve('regenerator/runtime')
}));production
You can use this module in production by setting option production or env variable NODE_ENV to production
app.use(browserify({
root: './public',
debug: true,
production: true // forse set production mode
}));or
NODE_ENV=production node app.js