select.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const { resolveScript } = require('./resolveScript')
  2. module.exports = function selectBlock(
  3. descriptor,
  4. scopeId,
  5. options,
  6. loaderContext,
  7. query,
  8. appendExtension
  9. ) {
  10. // template
  11. if (query.type === `template`) {
  12. if (appendExtension) {
  13. loaderContext.resourcePath += '.' + (descriptor.template.lang || 'html')
  14. }
  15. loaderContext.callback(
  16. null,
  17. descriptor.template.content,
  18. descriptor.template.map
  19. )
  20. return
  21. }
  22. // script
  23. if (query.type === `script`) {
  24. const script = resolveScript(descriptor, scopeId, options, loaderContext)
  25. if (appendExtension) {
  26. loaderContext.resourcePath += '.' + (script.lang || 'js')
  27. }
  28. loaderContext.callback(null, script.content, script.map)
  29. return
  30. }
  31. // styles
  32. if (query.type === `style` && query.index != null) {
  33. const style = descriptor.styles[query.index]
  34. if (appendExtension) {
  35. loaderContext.resourcePath += '.' + (style.lang || 'css')
  36. }
  37. loaderContext.callback(null, style.content, style.map)
  38. return
  39. }
  40. // custom
  41. if (query.type === 'custom' && query.index != null) {
  42. const block = descriptor.customBlocks[query.index]
  43. loaderContext.callback(null, block.content, block.map)
  44. return
  45. }
  46. }