compile-with-webpack.js 745 B

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