const fs = require('fs-extra') const path = require('path') // https://gist.github.com/samthor/64b114e4a4f539915a95b91ffd340acc 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, jsDirectory }) { this.targetDir = targetDir this.isModernBuild = isModernBuild this.unsafeInline = unsafeInline this.jsDirectory = jsDirectory } apply (compiler) { if (!this.isModernBuild) { this.applyLegacy(compiler) } else { this.applyModern(compiler) } } applyLegacy (compiler) { const ID = `vue-cli-legacy-bundle` compiler.hooks.compilation.tap(ID, compilation => { compilation.hooks.htmlWebpackPluginAlterAssetTags.tapAsync(ID, async (data, cb) => { // get stats, write to disk await fs.ensureDir(this.targetDir) const htmlName = path.basename(data.plugin.options.filename) // Watch out for output files in sub directories const htmlPath = path.dirname(data.plugin.options.filename) const tempFilename = path.join(this.targetDir, htmlPath, `legacy-assets-${htmlName}.json`) await fs.mkdirp(path.dirname(tempFilename)) await fs.writeFile(tempFilename, JSON.stringify(data.body)) cb() }) }) } applyModern (compiler) { const ID = `vue-cli-modern-bundle` compiler.hooks.compilation.tap(ID, compilation => { compilation.hooks.htmlWebpackPluginAlterAssetTags.tapAsync(ID, async (data, cb) => { // use