component-normalizer.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // this module is a runtime utility for cleaner component module output and will
  2. // be included in the final webpack user bundle
  3. module.exports = function normalizeComponent (
  4. rawScriptExports,
  5. compiledTemplate,
  6. scopeId,
  7. cssModules
  8. ) {
  9. var esModule
  10. var scriptExports = rawScriptExports = rawScriptExports || {}
  11. // ES6 modules interop
  12. var type = typeof rawScriptExports.default
  13. if (type === 'object' || type === 'function') {
  14. esModule = rawScriptExports
  15. scriptExports = rawScriptExports.default
  16. }
  17. // Vue.extend constructor export interop
  18. var options = typeof scriptExports === 'function'
  19. ? scriptExports.options
  20. : scriptExports
  21. // render functions
  22. if (compiledTemplate) {
  23. options.render = compiledTemplate.render
  24. options.staticRenderFns = compiledTemplate.staticRenderFns
  25. }
  26. // scopedId
  27. if (scopeId) {
  28. options._scopeId = scopeId
  29. }
  30. // inject cssModules
  31. if (cssModules) {
  32. var computed = Object.create(options.computed || null)
  33. Object.keys(cssModules).forEach(function (key) {
  34. var module = cssModules[key]
  35. computed[key] = function () { return module }
  36. })
  37. options.computed = computed
  38. }
  39. return {
  40. esModule: esModule,
  41. exports: scriptExports,
  42. options: options
  43. }
  44. }