compile-with-webpack.js 853 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. entry: path.resolve(__dirname, 'fixtures', file),
  7. module: {
  8. rules: [
  9. {
  10. test: /\.js$/,
  11. loader: 'babel-loader'
  12. },
  13. {
  14. test: /async-.*\.js$/,
  15. loader: require.resolve('./async-loader')
  16. },
  17. {
  18. test: /\.(png|woff2|css)$/,
  19. loader: 'file-loader',
  20. options: {
  21. name: '[name].[ext]'
  22. }
  23. }
  24. ]
  25. }
  26. }, extraConfig)
  27. const compiler = webpack(config)
  28. const fs = new MemoryFS()
  29. compiler.outputFileSystem = fs
  30. compiler.run((err, stats) => {
  31. expect(err).toBeFalsy()
  32. expect(stats.errors).toBeFalsy()
  33. cb(fs)
  34. })
  35. }