|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
868 bytes
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * @returns {string}
|
|---|
| 3 | */
|
|---|
| 4 | function getCurrentScriptSource() {
|
|---|
| 5 | // `document.currentScript` is the most accurate way to find the current script,
|
|---|
| 6 | // but is not supported in all browsers.
|
|---|
| 7 | if (document.currentScript) {
|
|---|
| 8 | return document.currentScript.getAttribute("src");
|
|---|
| 9 | }
|
|---|
| 10 |
|
|---|
| 11 | // Fallback to getting all scripts running in the document.
|
|---|
| 12 | var scriptElements = document.scripts || [];
|
|---|
| 13 | var scriptElementsWithSrc = Array.prototype.filter.call(scriptElements, function (element) {
|
|---|
| 14 | return element.getAttribute("src");
|
|---|
| 15 | });
|
|---|
| 16 | if (scriptElementsWithSrc.length > 0) {
|
|---|
| 17 | var currentScript = scriptElementsWithSrc[scriptElementsWithSrc.length - 1];
|
|---|
| 18 | return currentScript.getAttribute("src");
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | // Fail as there was no script to use.
|
|---|
| 22 | throw new Error("[webpack-dev-server] Failed to get current script source.");
|
|---|
| 23 | }
|
|---|
| 24 | export default getCurrentScriptSource; |
|---|
Note:
See
TracBrowser
for help on using the repository browser.