fix: SafariFix is not injected in client modern mode

This commit is contained in:
Clark Du 2019-01-08 13:20:48 +00:00
parent a053e58534
commit ecf76d91f1
2 changed files with 11 additions and 7 deletions

View File

@ -77,13 +77,6 @@ export default class ModernModePlugin {
}
})
// inject Safari 10 nomodule fix
data.body.push({
tagName: 'script',
closeTag: true,
innerHTML: ModernModePlugin.safariFix
})
// inject links for legacy assets as <script nomodule>
const fileName = data.plugin.options.filename
const legacyAssets = (await this.getAssets(fileName))
@ -100,6 +93,12 @@ export default class ModernModePlugin {
compilation.hooks.htmlWebpackPluginAfterHtmlProcessing.tap(ID, (data) => {
data.html = data.html.replace(/\snomodule="">/g, ' nomodule>')
// inject Safari 10 nomodule fix
data.html = data.html.replace(
/(<\/body\s*>)/i,
match => `<script>${ModernModePlugin.safariFix}</script>${match}`
)
})
})
}

View File

@ -39,6 +39,11 @@ describe('modern client mode (SSR)', () => {
].join(', '))
})
test('should contain safari fix script', async () => {
const response = await rp(url('/'))
expect(response).toContain('"noModule"')
})
// Close server and ask nuxt to stop listening to file changes
afterAll(async () => {
await nuxt.close()