forked from stolksdorf/vitreum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
require.js
26 lines (25 loc) · 941 Bytes
/
require.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const path = require('path');
const utils = require('./lib/utils.js');
const browserify = require('browserify');
const transform = require('./lib/transforms');
const getOpts = require('./lib/getopts.js');
module.exports = (filepath)=>{
const fullTargetPath = path.resolve(path.dirname(utils.getCaller().file), filepath);
const opts = getOpts({app:'', entry:{}}, fullTargetPath);
return new Promise((resolve, reject)=>{
browserify({
standalone : '___',
paths : opts.shared,
ignoreMissing : true,
node : true,
postFilter : (id, filepath, pkg)=>utils.shouldBundle(filepath, id, opts),
})
.require(fullTargetPath)
.transform((file)=>transform(file, opts), {global :true})
.bundle((err, buf)=>{
if(err) return reject(err);
const code = `'use strict'; let module = {}; (function() { ${buf.toString()}\nreturn module.exports;}())`;
return resolve(eval(code));
});
})
};