mirror of
https://bitbucket.org/bellord13/kit.git
synced 2026-11-13 19:06:11 +03:00
v2.0.1
This commit is contained in:
+23
-13
@@ -33,6 +33,7 @@ kit.config = kit.config || {};
|
||||
ES: 'ES', // CMAScript2020 or ES11
|
||||
UMD: 'UMD', // https://github.com/umdjs/umd
|
||||
HMD: 'HMD', // HandlerMD - function(require, exports, module, global){module.exports = {}; return {};}
|
||||
default: 'default',
|
||||
};
|
||||
/**
|
||||
* @memberOf kit
|
||||
@@ -54,7 +55,7 @@ kit.config = kit.config || {};
|
||||
isSetTimestamp: true,
|
||||
path: '',
|
||||
module: '', // file.js
|
||||
type: 'ES',
|
||||
type: 'default',
|
||||
handler: undefined,
|
||||
onRegister: function(plugin){},
|
||||
onLoad: function(plugin){},
|
||||
@@ -190,7 +191,7 @@ kit.config = kit.config || {};
|
||||
config.autoRequire = config.hasOwnProperty('autoRequire')?!!config.autoRequire:false;
|
||||
config.loadJsAfterModule = config.hasOwnProperty('loadJsAfterModule')?!!config.loadJsAfterModule:false;
|
||||
config.isSetTimestamp = config.hasOwnProperty('isSetTimestamp')?!!config.isSetTimestamp:true;
|
||||
config.type = config.type || 'ES';
|
||||
config.type = config.type || 'default';
|
||||
|
||||
if(typeof config.deps === 'string') {
|
||||
config.deps = [config.deps];
|
||||
@@ -321,6 +322,16 @@ kit.config = kit.config || {};
|
||||
return function (){
|
||||
return self.getScriptPromise(src);
|
||||
};
|
||||
} else if(typeof config.module === 'string' && config.module !== '' && config.type === 'default') {
|
||||
if (isAssetLoaded(src)) {
|
||||
self.config.debug && console.warn(`Plugin ${self.id}: Скрипт ${src} уже загружен!`);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
return function (){
|
||||
return self.getScriptPromise(src);
|
||||
};
|
||||
}
|
||||
}
|
||||
return;
|
||||
};
|
||||
@@ -420,29 +431,28 @@ kit.config = kit.config || {};
|
||||
};
|
||||
|
||||
var module = self.module;
|
||||
var exports = self.module.exports;
|
||||
|
||||
var installer = function(){
|
||||
|
||||
var __exports = undefined;
|
||||
if(self.config.type === 'ES' && typeof self.config.module === 'string' && self.config.module !== '') {
|
||||
__exports = (typeof exports === 'object' && exports.default !== undefined)
|
||||
?exports.default
|
||||
:exports;
|
||||
__exports = (typeof self.module.exports === 'object' && self.module.exports.default !== undefined)
|
||||
?self.module.exports.default
|
||||
:self.module.exports;
|
||||
} else if(self.config.type === 'UMD' && typeof self.config.module === 'string' && self.config.module !== '') {
|
||||
(function(require, exports, module, global){
|
||||
var self = global;
|
||||
eval(module.code);
|
||||
}.bind(global))
|
||||
.call(global, require, exports, module, global);
|
||||
__exports = (typeof exports === 'object' && exports.default !== undefined)
|
||||
?exports.default
|
||||
:exports;
|
||||
.call(global, require, self.module.exports, module, global);
|
||||
__exports = (typeof self.module.exports === 'object' && self.module.exports.default !== undefined)
|
||||
?self.module.exports.default
|
||||
:self.module.exports;
|
||||
} else if(self.config.type === 'HMD' && typeof self.config.handler === 'function') {
|
||||
__exports = self.config.handler.bind(global)
|
||||
.call(global, require, exports, module, global);
|
||||
if(__exports === undefined && exports){
|
||||
__exports = exports;
|
||||
.call(global, require, self.module.exports, module, global);
|
||||
if(__exports === undefined && self.module.exports){
|
||||
__exports = self.module.exports;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user