Skip to content

Commit 5b1709a

Browse files
authored
fix(target-lib): fix dynamic public path in a dynamic chunk in Firefox (vuejs#5247)
* fix(target-lib): fix dynamic public path in a dynmaic chunk in Firefox * fix: fix typo * feat: use external dependency `@soda/get-current-script` * fix: const -> var, as the `setPublicPath` file is not transpiled
1 parent db64c5b commit 5b1709a

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

packages/@vue/cli-service/lib/commands/build/setPublicPath.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
// This file is imported into lib/wc client bundles.
22

33
if (typeof window !== 'undefined') {
4+
var currentScript = window.document.currentScript
45
if (process.env.NEED_CURRENTSCRIPT_POLYFILL) {
5-
require('current-script-polyfill')
6+
var getCurrentScript = require('@soda/get-current-script')
7+
currentScript = getCurrentScript()
8+
9+
// for backward compatibility, because previously we directly included the polyfill
10+
if (!('currentScript' in document)) {
11+
Object.defineProperty(document, 'currentScript', { get: getCurrentScript })
12+
}
613
}
714

8-
var i
9-
if ((i = window.document.currentScript) && (i = i.src.match(/(.+\/)[^/]+\.js(\?.*)?$/))) {
10-
__webpack_public_path__ = i[1] // eslint-disable-line
15+
var src = currentScript && currentScript.src.match(/(.+\/)[^/]+\.js(\?.*)?$/)
16+
if (src) {
17+
__webpack_public_path__ = src[1] // eslint-disable-line
1118
}
1219
}
1320

packages/@vue/cli-service/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"dependencies": {
2626
"@intervolga/optimize-cssnano-plugin": "^1.0.5",
2727
"@soda/friendly-errors-webpack-plugin": "^1.7.1",
28+
"@soda/get-current-script": "^1.0.0",
2829
"@vue/cli-overlay": "^4.2.3",
2930
"@vue/cli-plugin-router": "^4.2.3",
3031
"@vue/cli-plugin-vuex": "^4.2.3",
@@ -45,7 +46,6 @@
4546
"copy-webpack-plugin": "^5.1.1",
4647
"css-loader": "^3.4.2",
4748
"cssnano": "^4.1.10",
48-
"current-script-polyfill": "^1.0.0",
4949
"debug": "^4.1.1",
5050
"default-gateway": "^5.0.5",
5151
"dotenv": "^8.2.0",

yarn.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -2306,6 +2306,11 @@
23062306
error-stack-parser "^2.0.0"
23072307
string-width "^2.0.0"
23082308

2309+
"@soda/get-current-script@^1.0.0":
2310+
version "1.0.0"
2311+
resolved "https://registry.yarnpkg.com/@soda/get-current-script/-/get-current-script-1.0.0.tgz#623aa40623550e3b94767cffeb096a6fb597ed09"
2312+
integrity sha512-9GvTek+7cVw7r+L7TNGOG1astZJWXz2h5q4BqMXl28KN+24iSCm1xo+RhZOZvwdT3bzNe9hD7riJc/lBoO7mgg==
2313+
23092314
"@szmarczak/http-timer@^1.1.2":
23102315
version "1.1.2"
23112316
resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-1.1.2.tgz#b1665e2c461a2cd92f4c1bbf50d5454de0d4b421"
@@ -6317,11 +6322,6 @@ csv-parser@^1.6.0:
63176322
minimist "^1.2.0"
63186323
ndjson "^1.4.0"
63196324

6320-
current-script-polyfill@^1.0.0:
6321-
version "1.0.0"
6322-
resolved "https://registry.yarnpkg.com/current-script-polyfill/-/current-script-polyfill-1.0.0.tgz#f31cf7e4f3e218b0726e738ca92a02d3488ef615"
6323-
integrity sha1-8xz35PPiGLBybnOMqSoC00iO9hU=
6324-
63256325
currently-unhandled@^0.4.1:
63266326
version "0.4.1"
63276327
resolved "https://registry.yarnpkg.com/currently-unhandled/-/currently-unhandled-0.4.1.tgz#988df33feab191ef799a61369dd76c17adf957ea"

0 commit comments

Comments
 (0)