add require module

This commit is contained in:
pengfei.zhou
2019-07-18 18:29:47 +08:00
parent 13c5719af1
commit 723c5455ab
9 changed files with 88 additions and 24 deletions

View File

@@ -6,7 +6,8 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "tsc -p .&& rollup -c && node ./bundle/bundle.js",
"build": "tsc -p . && rollup -c "
"build": "tsc -p . && rollup -c ",
"clean": "rm -rf build && rm -rf demo && rm -rf bundle"
},
"repository": {
"type": "https",

View File

@@ -9,7 +9,7 @@ export default [
output: {
name: "hego",
format: "iife",
file: "bundle/sandbox.js",
file: "bundle/hego-sandbox.js",
},
sourceMap: true,
plugins: [
@@ -21,12 +21,11 @@ export default [
input: "build/index.js",
output: {
format: "cjs",
file: "bundle/bundle.js",
file: "bundle/hego-lib.js",
},
sourceMap: true,
plugins: [
resolve({ jsnext: true, main: true }),
commonjs()
]
},
{

View File

@@ -14,11 +14,13 @@ import { loge } from "../util/log";
* hego.__require__,
* ])
* // load module in global scope
* Reflect.apply(hego.registerModule,this,[
* Reflect.apply(hego.jsRegisterModule,this,[
* moduleName,
* Reflect.apply(function(__module){
* return function(module,export,require){
* })(__module,__module.exports,hego.__require__)
* (function(module,exports,require){
* //module content
* })(__module,__module.exports,hego.__require__);
* return __module.exports
* },this,[{exports:{}}])
* ])
*
@@ -83,7 +85,7 @@ export class Context {
})
})
}
registor(instance: Object) {
register(instance: Object) {
this.entity = instance
}
}

View File

@@ -5,7 +5,7 @@ export function Registor<T extends { new(...args: any[]): {} }>(constructor: T)
const ret = class extends constructor {
context = context
}
context.registor(new ret)
context.register(new ret)
return ret
}