Dashboard sipadu mbip
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. 'use strict'
  2. const req = require('import-cwd')
  3. /**
  4. * Plugin Loader
  5. *
  6. * @private
  7. * @method load
  8. *
  9. * @param {String} plugin PostCSS Plugin Name
  10. * @param {Object} options PostCSS Plugin Options
  11. *
  12. * @return {Function} PostCSS Plugin
  13. */
  14. const load = (plugin, options, file) => {
  15. try {
  16. if (
  17. options === null ||
  18. options === undefined ||
  19. Object.keys(options).length === 0
  20. ) {
  21. return req(plugin)
  22. } else {
  23. return req(plugin)(options)
  24. }
  25. } catch (err) {
  26. throw new Error(`Loading PostCSS Plugin failed: ${err.message}\n\n(@${file})`)
  27. }
  28. }
  29. /**
  30. * Load Plugins
  31. *
  32. * @private
  33. * @method plugins
  34. *
  35. * @param {Object} config PostCSS Config Plugins
  36. *
  37. * @return {Array} plugins PostCSS Plugins
  38. */
  39. const plugins = (config, file) => {
  40. let plugins = []
  41. if (Array.isArray(config.plugins)) {
  42. plugins = config.plugins.filter(Boolean)
  43. } else {
  44. plugins = Object.keys(config.plugins)
  45. .filter((plugin) => {
  46. return config.plugins[plugin] !== false ? plugin : ''
  47. })
  48. .map((plugin) => {
  49. return load(plugin, config.plugins[plugin], file)
  50. })
  51. }
  52. if (plugins.length && plugins.length > 0) {
  53. plugins.forEach((plugin, i) => {
  54. if (plugin.postcss) {
  55. plugin = plugin.postcss
  56. }
  57. if (plugin.default) {
  58. plugin = plugin.default
  59. }
  60. if (
  61. // eslint-disable-next-line
  62. !(typeof plugin === 'object' && Array.isArray(plugin.plugins) ||
  63. typeof plugin === 'function')
  64. ) {
  65. throw new TypeError(`Invalid PostCSS Plugin found at: plugins[${i}]\n\n(@${file})`)
  66. }
  67. })
  68. }
  69. return plugins
  70. }
  71. module.exports = plugins