mini-program-global-runtime-webpack-plugin
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -6,5 +6,5 @@ const RuntimeGlobals = require("webpack").RuntimeGlobals; | ||
class MiniProgramGlobalRuntimeWebpackPlugin { | ||
reBuildGlobal = true; | ||
constructor(options = {}) { | ||
this.reBuildGlobal = true; | ||
if (options && options.reBuildGlobal === false) { | ||
@@ -11,0 +11,0 @@ this.reBuildGlobal = false; |
@@ -8,8 +8,6 @@ "use strict"; | ||
class MiniProgramGlobalProperty extends RuntimeModule { | ||
globalObject = "global"; | ||
constructor(globalObject) { | ||
super("global"); | ||
this.globalObject = this.globalObject || globalObject; | ||
this.globalObject = globalObject || "global"; | ||
} | ||
@@ -16,0 +14,0 @@ |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
@@ -10,42 +9,40 @@ | ||
class MiniProgramGlobalRuntimeModule extends RuntimeModule { | ||
globalObject = "global"; | ||
constructor(globalObject) { | ||
super("global"); | ||
constructor(globalObject) { | ||
super("global"); | ||
this.globalObject = this.globalObject || globalObject; | ||
} | ||
this.globalObject = globalObject || "global"; | ||
} | ||
/** | ||
* @returns {string} runtime code | ||
*/ | ||
generate() { | ||
return Template.asString([ | ||
`${RuntimeGlobals.global} = (function() {`, | ||
Template.indent([ | ||
"if (typeof globalThis === 'object') return globalThis;", | ||
`if (typeof ${this.globalObject} === 'object') return ${this.globalObject};`, | ||
"try {", | ||
Template.indent( | ||
// This works in non-strict mode | ||
// or | ||
// This works if eval is allowed (see CSP) | ||
"return this || new Function('return this')();" | ||
), | ||
"} catch (e) {", | ||
Template.indent( | ||
// This works if the window reference is available | ||
"if (typeof window === 'object') return window;" | ||
), | ||
"}" | ||
// It can still be `undefined`, but nothing to do about it... | ||
// We return `undefined`, instead of nothing here, so it's | ||
// easier to handle this case: | ||
// if (!global) { … } | ||
]), | ||
"})();" | ||
]); | ||
} | ||
/** | ||
* @returns {string} runtime code | ||
*/ | ||
generate() { | ||
return Template.asString([ | ||
`${RuntimeGlobals.global} = (function() {`, | ||
Template.indent([ | ||
"if (typeof globalThis === 'object') return globalThis;", | ||
`if (typeof ${this.globalObject} === 'object') return ${this.globalObject};`, | ||
"try {", | ||
Template.indent( | ||
// This works in non-strict mode | ||
// or | ||
// This works if eval is allowed (see CSP) | ||
"return this || new Function('return this')();", | ||
), | ||
"} catch (e) {", | ||
Template.indent( | ||
// This works if the window reference is available | ||
"if (typeof window === 'object') return window;", | ||
), | ||
"}", | ||
// It can still be `undefined`, but nothing to do about it... | ||
// We return `undefined`, instead of nothing here, so it's | ||
// easier to handle this case: | ||
// if (!global) { … } | ||
]), | ||
"})();", | ||
]); | ||
} | ||
} | ||
module.exports = MiniProgramGlobalRuntimeModule; |
{ | ||
"name": "mini-program-global-runtime-webpack-plugin", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "生成小程序全局变量", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8303
175