compile-with-webpack.js 878 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import path from 'path'
  2. import webpack from 'webpack'
  3. import MemoryFS from 'memory-fs'
  4. export function compileWithWebpack (file, extraConfig, cb) {
  5. const config = Object.assign({
  6. mode: 'development',
  7. entry: path.resolve(__dirname, 'fixtures', file),
  8. module: {
  9. rules: [
  10. {
  11. test: /\.js$/,
  12. loader: 'babel-loader'
  13. },
  14. {
  15. test: /async-.*\.js$/,
  16. loader: require.resolve('./async-loader')
  17. },
  18. {
  19. test: /\.(png|woff2|css)$/,
  20. loader: 'file-loader',
  21. options: {
  22. name: '[name].[ext]'
  23. }
  24. }
  25. ]
  26. }
  27. }, extraConfig)
  28. const compiler = webpack(config)
  29. const fs = new MemoryFS()
  30. compiler.outputFileSystem = fs
  31. compiler.run((err, stats) => {
  32. expect(err).toBeFalsy()
  33. expect(stats.errors).toBeFalsy()
  34. cb(fs)
  35. })
  36. }