index.js 637 B

12345678910111213141516171819202122
  1. 'use strict'
  2. var loaderUtils = require('loader-utils')
  3. module.exports = function (content, map, meta) {
  4. var options = Object.assign({}, loaderUtils.getOptions(this))
  5. if (typeof options.plugins === 'function') {
  6. options.plugins = options.plugins(this)
  7. }
  8. if (!Array.isArray(options.plugins) || options.plugins.length === 0) {
  9. return content
  10. }
  11. var callback = this.async()
  12. import("imagemin")
  13. .then(function (imagemin) {
  14. imagemin.default.buffer(content, options)
  15. .then(function (buffer) { callback(null, buffer) })
  16. })
  17. .catch(function (error) { callback(error) })
  18. }
  19. module.exports.raw = true