parent
23a144fb8b
commit
b7aab95519
@ -1,4 +1,4 @@ |
||||
# run 2 servers and make sure they close together |
||||
|
||||
beefy frame.js:bundle.js 9001 --live & |
||||
beefy example/index.js:bundle.js index.js:zero.js --cwd example/ 9002 --live --open |
||||
beefy frame.js:bundle.js 9001 --live -- -t [ babelify --global --presets [ es2015 ] ] & |
||||
beefy example/index.js:bundle.js index.js:zero.js --cwd example/ 9002 --live --open -- -t [ babelify --global --presets [ es2015 ] ] |
@ -0,0 +1,88 @@ |
||||
const express = require('express') |
||||
const browserify = require('browserify') |
||||
const watchify = require('watchify') |
||||
const babelify = require('babelify') |
||||
const path = require('path') |
||||
|
||||
const zeroBundle = createBundle('./index.js') |
||||
const controllerBundle = createBundle('./controller.js') |
||||
const appBundle = createBundle('./example/index.js') |
||||
|
||||
//
|
||||
// Iframe Server
|
||||
//
|
||||
|
||||
// beefy frame.js:bundle.js 9001 --live -- -t [ babelify --global --presets [ es2015 ] ]
|
||||
|
||||
const iframeServer = express() |
||||
|
||||
// serve controller bundle
|
||||
iframeServer.get('/controller.js', function(req, res){ |
||||
res.send(controllerBundle.latest) |
||||
}) |
||||
|
||||
// serve static
|
||||
iframeServer.use(express.static('./server')) |
||||
|
||||
iframeServer.listen('9001') |
||||
|
||||
|
||||
//
|
||||
// Dapp Server
|
||||
//
|
||||
|
||||
// beefy example/index.js:bundle.js index.js:zero.js --cwd example/ 9002 --live --open -- -t [ babelify --global --presets [ es2015 ] ]
|
||||
|
||||
const dappServer = express() |
||||
|
||||
|
||||
// serve metamask-lib bundle
|
||||
dappServer.get('/zero.js', function(req, res){ |
||||
res.send(zeroBundle.latest) |
||||
}) |
||||
|
||||
// serve dapp bundle
|
||||
dappServer.get('/app.js', function(req, res){ |
||||
res.send(appBundle.latest) |
||||
}) |
||||
|
||||
// serve static
|
||||
dappServer.use(express.static('./example')) |
||||
|
||||
|
||||
dappServer.listen('9002') |
||||
|
||||
|
||||
function createBundle(entryPoint){ |
||||
|
||||
var bundleContainer = {} |
||||
|
||||
var bundler = browserify({ |
||||
entries: [entryPoint], |
||||
cache: {}, |
||||
packageCache: {}, |
||||
plugin: [watchify], |
||||
}) |
||||
|
||||
var bablePreset = path.resolve(__dirname, '../node_modules/babel-preset-es2015') |
||||
|
||||
bundler.transform(babelify, { |
||||
global: true, |
||||
presets: [bablePreset], |
||||
}) |
||||
|
||||
|
||||
bundler.on('update', bundle) |
||||
bundle() |
||||
|
||||
return bundleContainer |
||||
|
||||
function bundle() { |
||||
bundler.bundle(function(err, result){ |
||||
if (err) throw err |
||||
console.log(`Bundle updated! (${entryPoint})`) |
||||
bundleContainer.latest = result.toString() |
||||
}) |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue