koa-browserify

2019-09-12

koa-browserify是什么

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

koa-browserify使用教程帮助文档

koa-browserify

middleware for koa.jsthat 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

  • rootroot folder for scripts
  • debugenable soucemaps
  • productionenable production mode. In production soucemaps not working and code is minified
  • transformyou 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 jsxfiles to jscode

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 productionor envvariable NODE_ENVto production

app.use(browserify({
    root: './public',
    debug: true,
    production: true // forse set production mode
}));

or

NODE_ENV=production node app.js

上一篇:teeleader-socketstream
下一篇:一个不成熟的前端leader的心理话
相关教程
关注微信

扫码加入 JavaScript 社区

相关文章

首次访问,需要验证
微信扫码,关注即可
(仅需验证一次)

欢迎加入 JavaScript 社区

号内回复关键字:

回到顶部