mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-04-28 15:59:34 -05:00
fix: set the path of safari-no-module-fix.js correctly (#3647)
fixes #3033
This commit is contained in:
@@ -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')
|
||||
}])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
@@ -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)
|
||||
@@ -92,7 +90,7 @@ class ModernModePlugin {
|
||||
tagName: 'script',
|
||||
closeTag: true,
|
||||
attributes: {
|
||||
src: safariFixPath
|
||||
src: fullSafariFixPath
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user