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.

39 lines
898 B

4 years ago
  1. 'use strict'
  2. var path = require('path')
  3. var webpack = require('webpack')
  4. var MemoryFS = require('memory-fs')
  5. module.exports = function (entry, options) {
  6. var compiler = webpack({
  7. context: __dirname,
  8. entry: entry,
  9. output: {
  10. path: path.resolve(__dirname),
  11. filename: 'bundle.js'
  12. },
  13. mode: 'none',
  14. module: {
  15. rules: [{
  16. test: /./,
  17. use: [
  18. {
  19. loader: 'file-loader',
  20. options: {
  21. name: 'image'
  22. }
  23. },
  24. {
  25. loader: path.resolve(__dirname, '../index.js'),
  26. options: options
  27. }
  28. ]
  29. }]
  30. }
  31. })
  32. compiler.outputFileSystem = new MemoryFS()
  33. return new Promise(function (resolve, reject) {
  34. compiler.run(function (error, stats) {
  35. return error ? reject(error) : resolve(stats.compilation.assets.image.source())
  36. })
  37. })
  38. }