feat(ssr): auto-remove initial state script if prod (#6763)

close #6761
This commit is contained in:
Mark Brouch 2017-10-10 10:06:47 -05:00 committed by Evan You
parent dff85b230a
commit 2d32b5d1b6

View File

@ -191,10 +191,13 @@ export default class TemplateRenderer {
contextKey = 'state',
windowKey = '__INITIAL_STATE__'
} = options || {}
const autoRemove = process.env.NODE_ENV === 'production'
? '(function(){var s;(s=document.currentScript||document.scripts[document.scripts.length-1]).parentNode.removeChild(s);}());'
: ''
return context[contextKey]
? `<script>window.${windowKey}=${
serialize(context[contextKey], { isJSON: true })
}</script>`
}${autoRemove}</script>`
: ''
}