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.

20 lines
577 B

4 years ago
  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. require('imagemin')
  13. .buffer(content, options)
  14. .then(function (buffer) { callback(null, buffer) })
  15. .catch(function (error) { callback(error) })
  16. }
  17. module.exports.raw = true