hotReload.js 824 B

12345678910111213141516171819202122232425262728293031
  1. const hotReloadAPIPath = JSON.stringify(require.resolve('vue-hot-reload-api'))
  2. const genTemplateHotReloadCode = (id, request) => {
  3. return `
  4. module.hot.accept(${request}, function () {
  5. api.rerender('${id}', {
  6. render: render,
  7. staticRenderFns: staticRenderFns
  8. })
  9. })
  10. `.trim()
  11. }
  12. exports.genHotReloadCode = (id, functional, templateRequest) => {
  13. return `
  14. /* hot reload */
  15. if (module.hot) {
  16. var api = require(${hotReloadAPIPath})
  17. api.install(require('vue'))
  18. if (api.compatible) {
  19. module.hot.accept()
  20. if (!api.isRecorded('${id}')) {
  21. api.createRecord('${id}', component.options)
  22. } else {
  23. api.${functional ? 'rerender' : 'reload'}('${id}', component.options)
  24. }
  25. ${templateRequest ? genTemplateHotReloadCode(id, templateRequest) : ''}
  26. }
  27. }
  28. `.trim()
  29. }