build.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * @description 插件构建文件模板
  3. */
  4. module.exports = {
  5. /**
  6. * @description 入口文件
  7. * @type {String}
  8. * @default 'index.js'
  9. */
  10. main: 'index.js',
  11. /**
  12. * @description 支持的平台
  13. * @type {String[]}
  14. * @default ['mp-weixin','mp-qq','mp-baidu','mp-alipay','mp-toutiao','uni-app']
  15. */
  16. platform: ['mp-weixin', 'mp-qq', 'mp-baidu', 'mp-alipay', 'mp-toutiao', 'uni-app'],
  17. /**
  18. * @description 要被添加到模板文件中的标签(将被添加到 src/node/node.wxml)
  19. * 必须要有 wx:if 表明什么情况下使用该标签
  20. * n 表示标签结构体,<node> 标签用于递归显示子节点(可参考源文件中的写法)
  21. * @type {String}
  22. */
  23. template: '',
  24. /**
  25. * @description 用于处理模板中事件的方法(将被添加到 src/node/node.js)
  26. * 需要触发顶层组件的事件请使用 this.root.triggerEvent
  27. * @type {Object}
  28. */
  29. methods: {
  30. },
  31. /**
  32. * @description 用于模板文件的 css 样式(将被添加到 src/node/node.wxss)
  33. * @type {String}
  34. */
  35. style: '',
  36. /**
  37. * @description 要被引入到模板文件的 css 文件路径(将被添加到 src/node/node.wxss)
  38. * @type {String|String[]}
  39. */
  40. import: [],
  41. /**
  42. * @description 在模板中需要使用的组件或插件列表(将被添加到 src/node/node.json)
  43. * @type {Object}
  44. */
  45. usingComponents: {
  46. },
  47. /**
  48. * @description 自定义文件处理器
  49. * 如果上述处理还无法满足要求,可以在此方法中进行处理
  50. * 所有 src 目录下的文件和本插件目录下的文件都会经过此方法的处理
  51. * @param {Vinyl} file 关于该文件对象的格式可参考 https://github.com/gulpjs/vinyl#instance-methods
  52. * @param {String} platform 平台
  53. */
  54. handler (file, platform) {
  55. let content = file.contents.toString()
  56. // 进行处理
  57. if (platform === 'xxx') {
  58. content = content.replace('aaa', 'bbb')
  59. }
  60. file.contents = Buffer.from(content)
  61. }
  62. }