File tree Expand file tree Collapse file tree 2 files changed +27
-30
lines changed Expand file tree Collapse file tree 2 files changed +27
-30
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1- import getCurrentScriptSource from "./getCurrentScriptSource.js" ;
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+ const scriptElements = document . scripts || [ ] ;
13+ const scriptElementsWithSrc = Array . prototype . filter . call (
14+ scriptElements ,
15+ ( element ) => element . getAttribute ( "src" ) ,
16+ ) ;
17+
18+ if ( scriptElementsWithSrc . length > 0 ) {
19+ const currentScript =
20+ scriptElementsWithSrc [ scriptElementsWithSrc . length - 1 ] ;
21+
22+ return currentScript . getAttribute ( "src" ) ;
23+ }
24+
25+ // Fail as there was no script to use.
26+ throw new Error ( "[webpack-dev-server] Failed to get current script source." ) ;
27+ }
228
329/**
430 * @param {string } resourceQuery
You can’t perform that action at this time.
0 commit comments