koa-browserify

2019-09-12 admin

koa-browserify是什么

什么是koa-browserify,koa-browserify ------------

koa-browserify使用教程帮助文档

koa-browserify

middleware for koa.js that compile CommonJS modules

install

npm i koa-browserify

example

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

  • root root folder for scripts
  • debug enable soucemaps
  • production enable production mode. In production soucemaps not working and code is minified
  • transform you 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.
  • runtime you 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

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-74956.html

文章标题:koa-browserify

回到顶部