Jelajahi Sumber

remove "define" object temporarily if defined (fix #671)

Gildas 4 tahun lalu
induk
melakukan
9e9fa4036c
1 mengubah file dengan 3 tambahan dan 1 penghapusan
  1. 3 1
      cli/back-ends/common/scripts.js

+ 3 - 1
cli/back-ends/common/scripts.js

@@ -42,7 +42,8 @@ const WEB_SCRIPTS = [
 
 exports.get = async options => {
 	const basePath = "../../../";
-	let scripts = await readScriptFiles(INDEX_SCRIPTS, basePath);
+	let scripts = "let _singleFileDefine; if (define) { _singleFileDefine = define; define = null }";
+	scripts += await readScriptFiles(INDEX_SCRIPTS, basePath);
 	const webScripts = {};
 	await Promise.all(WEB_SCRIPTS.map(async path => webScripts[path] = await readScriptFile(path, basePath)));
 	scripts += "window.singlefile.getFileContent = filename => (" + JSON.stringify(webScripts) + ")[filename];\n";
@@ -51,6 +52,7 @@ exports.get = async options => {
 	if (options.browserStylesheets && options.browserStylesheets.length) {
 		scripts += "addEventListener(\"load\",()=>{const styleElement=document.createElement(\"style\");styleElement.textContent=" + JSON.stringify(await readScriptFiles(options.browserStylesheets, "")) + ";document.body.appendChild(styleElement);});";
 	}
+	scripts += "if (_singleFileDefine) { define = _singleFileDefine; _singleFileDefine = null }";
 	return scripts;
 };