Skip to content

Commit

Permalink
fix: set the path of safari-no-module-fix.js correctly (#3647)
Browse files Browse the repository at this point in the history
fixes #3033
  • Loading branch information
sodatea committed Mar 27, 2019
1 parent 614367d commit 10296ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Expand Up @@ -28,7 +28,10 @@ module.exports = (api, args, options) => {
.use(ModernModePlugin, [{
targetDir,
isModernBuild: true,
unsafeInline: args['unsafe-inline']
unsafeInline: args['unsafe-inline'],
// as we may generate an addition file asset (if `no-unsafe-inline` specified)
// we need to provide the correct directory for that file to place in
jsDirectory: require('../../util/getAssetPath')(options, 'js')
}])
}
}
Expand Down
12 changes: 5 additions & 7 deletions packages/@vue/cli-service/lib/webpack/ModernModePlugin.js
Expand Up @@ -5,10 +5,11 @@ const path = require('path')
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()}}();`

class ModernModePlugin {
constructor ({ targetDir, isModernBuild, unsafeInline }) {
constructor ({ targetDir, isModernBuild, unsafeInline, jsDirectory }) {
this.targetDir = targetDir
this.isModernBuild = isModernBuild
this.unsafeInline = unsafeInline
this.jsDirectory = jsDirectory
}

apply (compiler) {
Expand Down Expand Up @@ -75,11 +76,8 @@ class ModernModePlugin {
})
} else {
// inject the fix as an external script
const safariFixPath = legacyAssets[0].attributes.src
.split('/')
.slice(0, -1)
.concat(['safari-nomodule-fix.js'])
.join('/')
const safariFixPath = path.join(this.jsDirectory, 'safari-nomodule-fix.js')
const fullSafariFixPath = path.join(compilation.options.output.publicPath, safariFixPath)
compilation.assets[safariFixPath] = {
source: function () {
return new Buffer(safariFix)
Expand All @@ -92,7 +90,7 @@ class ModernModePlugin {
tagName: 'script',
closeTag: true,
attributes: {
src: safariFixPath
src: fullSafariFixPath
}
})
}
Expand Down

0 comments on commit 10296ff

Please sign in to comment.