Skip to content

Commit 10296ff

Browse files
authoredMar 27, 2019
fix: set the path of safari-no-module-fix.js correctly (#3647)
fixes #3033
1 parent 614367d commit 10296ff

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed
 

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ module.exports = (api, args, options) => {
2828
.use(ModernModePlugin, [{
2929
targetDir,
3030
isModernBuild: true,
31-
unsafeInline: args['unsafe-inline']
31+
unsafeInline: args['unsafe-inline'],
32+
// as we may generate an addition file asset (if `no-unsafe-inline` specified)
33+
// we need to provide the correct directory for that file to place in
34+
jsDirectory: require('../../util/getAssetPath')(options, 'js')
3235
}])
3336
}
3437
}

‎packages/@vue/cli-service/lib/webpack/ModernModePlugin.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ const path = require('path')
55
const safariFix = `!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()},!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();`
66

77
class ModernModePlugin {
8-
constructor ({ targetDir, isModernBuild, unsafeInline }) {
8+
constructor ({ targetDir, isModernBuild, unsafeInline, jsDirectory }) {
99
this.targetDir = targetDir
1010
this.isModernBuild = isModernBuild
1111
this.unsafeInline = unsafeInline
12+
this.jsDirectory = jsDirectory
1213
}
1314

1415
apply (compiler) {
@@ -75,11 +76,8 @@ class ModernModePlugin {
7576
})
7677
} else {
7778
// inject the fix as an external script
78-
const safariFixPath = legacyAssets[0].attributes.src
79-
.split('/')
80-
.slice(0, -1)
81-
.concat(['safari-nomodule-fix.js'])
82-
.join('/')
79+
const safariFixPath = path.join(this.jsDirectory, 'safari-nomodule-fix.js')
80+
const fullSafariFixPath = path.join(compilation.options.output.publicPath, safariFixPath)
8381
compilation.assets[safariFixPath] = {
8482
source: function () {
8583
return new Buffer(safariFix)
@@ -92,7 +90,7 @@ class ModernModePlugin {
9290
tagName: 'script',
9391
closeTag: true,
9492
attributes: {
95-
src: safariFixPath
93+
src: fullSafariFixPath
9694
}
9795
})
9896
}

0 commit comments

Comments
 (0)
Please sign in to comment.