From b1011da0f159a20cca54c9b6ac8177aaf06b78da Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Fri, 6 Mar 2020 17:48:21 +0800 Subject: [PATCH 1/4] fix(target-lib): fix dynamic public path in a dynmaic chunk in Firefox --- .../lib/commands/build/getCurrentScript.js | 62 +++++++++++++++++++ .../lib/commands/build/setPublicPath.js | 7 ++- 2 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 packages/@vue/cli-service/lib/commands/build/getCurrentScript.js diff --git a/packages/@vue/cli-service/lib/commands/build/getCurrentScript.js b/packages/@vue/cli-service/lib/commands/build/getCurrentScript.js new file mode 100644 index 0000000000..185870cf33 --- /dev/null +++ b/packages/@vue/cli-service/lib/commands/build/getCurrentScript.js @@ -0,0 +1,62 @@ +/* eslint-disable */ +// adapted from https://github.com/amiller-gh/currentScript-polyfill/blob/master/currentScript.js +// added support for Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1620505 +function getCurrentScript () { + // IE 8-10 support script readyState + // IE 11+ support stack trace + // Firefox supports err.fileName + try { + throw new Error(); + } + catch (err) { + // Find the second match for the "at" string to get file src url from stack. + // Specifically works with the format of stack traces in IE. + var i = 0, + stackDetails = (/.*at [^(]*\((.*):(.+):(.+)\)$/ig).exec(err.stack), + scriptLocation = err.fileName || (stackDetails && stackDetails[1]) || false, + line = (stackDetails && stackDetails[2]) || false, + currentLocation = document.location.href.replace(document.location.hash, ''), + pageSource, + inlineScriptSourceRegExp, + inlineScriptSource, + scripts = document.getElementsByTagName('script'); // Live NodeList collection + + if (scriptLocation === currentLocation) { + pageSource = document.documentElement.outerHTML; + inlineScriptSourceRegExp = new RegExp('(?:[^\\n]+?\\n){0,' + (line - 2) + '}[^<]*