Last active
February 20, 2016 00:50
-
-
Save falsandtru/390683f4880aa3e4467a to your computer and use it in GitHub Desktop.
TypeScript bundled file header for an isomorphic single file node module.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// # TypeScript compilation and bundling | |
// $ tsc -t es5 -m amd --moduleResolution node --outFile bundle.js mylib.ts src/a.ts src/b.ts | |
// ^~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~ | |
// # terminal | |
// $ node | |
// > require('./bundle.js') | |
// 1 2 | |
// { default: 3 } | |
// | |
// # browser console | |
// 1 2 | |
// > mylib | |
// { default: 3 } | |
// | |
// # sample product | |
// https://github.com/falsandtru/arch-stream | |
// $ npm i arch-stream | |
// | |
define = typeof define === 'function' && define.amd | |
? define | |
: (function () { | |
'use strict'; | |
var name = 'mylib', | |
workspace = {}; | |
return function define(m, rs, f) { | |
return !f | |
? void define(name, m, rs) | |
: void f.apply(this, rs.map(function (r) { | |
switch (r) { | |
case 'require': { | |
return typeof require === 'function' ? require : void 0; | |
} | |
case 'exports': { | |
return m.indexOf('/') === -1 | |
? workspace[m] = typeof exports === 'undefined' ? self[m] = self[m] || {} : exports | |
: workspace[m] = workspace.hasOwnProperty(m) ? workspace[m] : {}; | |
} | |
default: { | |
return r.slice(-2) === '.d' && {} | |
|| workspace.hasOwnProperty(r) && workspace[r] | |
|| typeof require === 'function' && require(r) | |
|| self[r]; | |
} | |
} | |
})); | |
}; | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/a.ts | |
export default 1; | |
// src/b.ts | |
import a from './a'; | |
export var b = a + 1; | |
// mylib.ts | |
import a from './src/a'; | |
import {b} from './src/b'; | |
export default a + b; | |
console.log(a, b); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment