You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
824 B

4 years ago
  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. }