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.

57 lines
1.2 KiB

4 years ago
  1. module.exports = function selectBlock (
  2. descriptor,
  3. loaderContext,
  4. query,
  5. appendExtension
  6. ) {
  7. // template
  8. if (query.type === `template`) {
  9. if (appendExtension) {
  10. loaderContext.resourcePath += '.' + (descriptor.template.lang || 'html')
  11. }
  12. loaderContext.callback(
  13. null,
  14. descriptor.template.content,
  15. descriptor.template.map
  16. )
  17. return
  18. }
  19. // script
  20. if (query.type === `script`) {
  21. if (appendExtension) {
  22. loaderContext.resourcePath += '.' + (descriptor.script.lang || 'js')
  23. }
  24. loaderContext.callback(
  25. null,
  26. descriptor.script.content,
  27. descriptor.script.map
  28. )
  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(
  38. null,
  39. style.content,
  40. style.map
  41. )
  42. return
  43. }
  44. // custom
  45. if (query.type === 'custom' && query.index != null) {
  46. const block = descriptor.customBlocks[query.index]
  47. loaderContext.callback(
  48. null,
  49. block.content,
  50. block.map
  51. )
  52. return
  53. }
  54. }