Skip to content

Commit

Permalink
fix(target-lib): fix dynamic public path in a dynamic chunk in Firefox (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
sodatea committed Mar 23, 2020
1 parent db64c5b commit 5b1709a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
15 changes: 11 additions & 4 deletions packages/@vue/cli-service/lib/commands/build/setPublicPath.js
@@ -1,13 +1,20 @@
// This file is imported into lib/wc client bundles.

if (typeof window !== 'undefined') {
var currentScript = window.document.currentScript
if (process.env.NEED_CURRENTSCRIPT_POLYFILL) {
require('current-script-polyfill')
var getCurrentScript = require('@soda/get-current-script')
currentScript = getCurrentScript()

// for backward compatibility, because previously we directly included the polyfill
if (!('currentScript' in document)) {

This comment has been minimized.

Copy link
@social4hyq

social4hyq Apr 10, 2020

这样写会导致IE11下堆栈溢出,因为@soda/get-current-script 里面会调用 document.currentScript,死循环了

This comment has been minimized.

Copy link
@sodatea

sodatea Jun 4, 2020

Author Member

Fixed in @soda/get-current-script v1.0.1

Object.defineProperty(document, 'currentScript', { get: getCurrentScript })
}
}

var i
if ((i = window.document.currentScript) && (i = i.src.match(/(.+\/)[^/]+\.js(\?.*)?$/))) {
__webpack_public_path__ = i[1] // eslint-disable-line
var src = currentScript && currentScript.src.match(/(.+\/)[^/]+\.js(\?.*)?$/)
if (src) {
__webpack_public_path__ = src[1] // eslint-disable-line
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/package.json
Expand Up @@ -25,6 +25,7 @@
"dependencies": {
"@intervolga/optimize-cssnano-plugin": "^1.0.5",
"@soda/friendly-errors-webpack-plugin": "^1.7.1",
"@soda/get-current-script": "^1.0.0",
"@vue/cli-overlay": "^4.2.3",
"@vue/cli-plugin-router": "^4.2.3",
"@vue/cli-plugin-vuex": "^4.2.3",
Expand All @@ -45,7 +46,6 @@
"copy-webpack-plugin": "^5.1.1",
"css-loader": "^3.4.2",
"cssnano": "^4.1.10",
"current-script-polyfill": "^1.0.0",
"debug": "^4.1.1",
"default-gateway": "^5.0.5",
"dotenv": "^8.2.0",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Expand Up @@ -2306,6 +2306,11 @@
error-stack-parser "^2.0.0"
string-width "^2.0.0"

"@soda/get-current-script@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@soda/get-current-script/-/get-current-script-1.0.0.tgz#623aa40623550e3b94767cffeb096a6fb597ed09"
integrity sha512-9GvTek+7cVw7r+L7TNGOG1astZJWXz2h5q4BqMXl28KN+24iSCm1xo+RhZOZvwdT3bzNe9hD7riJc/lBoO7mgg==

"@szmarczak/http-timer@^1.1.2":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-1.1.2.tgz#b1665e2c461a2cd92f4c1bbf50d5454de0d4b421"
Expand Down Expand Up @@ -6317,11 +6322,6 @@ csv-parser@^1.6.0:
minimist "^1.2.0"
ndjson "^1.4.0"

current-script-polyfill@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/current-script-polyfill/-/current-script-polyfill-1.0.0.tgz#f31cf7e4f3e218b0726e738ca92a02d3488ef615"
integrity sha1-8xz35PPiGLBybnOMqSoC00iO9hU=

currently-unhandled@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/currently-unhandled/-/currently-unhandled-0.4.1.tgz#988df33feab191ef799a61369dd76c17adf957ea"
Expand Down

0 comments on commit 5b1709a

Please sign in to comment.