diff --git a/packages/@vue/cli-service/lib/commands/build/setPublicPath.js b/packages/@vue/cli-service/lib/commands/build/setPublicPath.js index 8968ca36be..e298abdc47 100644 --- a/packages/@vue/cli-service/lib/commands/build/setPublicPath.js +++ b/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)) { + 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 } } diff --git a/packages/@vue/cli-service/package.json b/packages/@vue/cli-service/package.json index 4c656313ec..6706e174bb 100644 --- a/packages/@vue/cli-service/package.json +++ b/packages/@vue/cli-service/package.json @@ -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", @@ -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", diff --git a/yarn.lock b/yarn.lock index 0886cbe102..0d738bde3e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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"