-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpreprocessor.js
More file actions
39 lines (27 loc) · 887 Bytes
/
Copy pathpreprocessor.js
File metadata and controls
39 lines (27 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
// Adapted from https://github.com/ColCh/jest-webpack/blob/f8e02b7a51da48c55395392e61d9c03789e43911/preprocessor.js
var webpack = require('webpack');
var MemoryFileSystem = require('memory-fs');
var fs = new MemoryFileSystem();
module.exports = {
process: function (src, filename) {
var options = require('./webpack.config.test.js');
options.entry = filename;
options.output.path = '/';
options.output.filename = filename;
var compiler = webpack(options);
compiler.outputFileSystem = fs;
var stats = null;
compiler.run(function() {
console.log("\nwebpack compile "+ filename)
stats = true;
});
while (stats === null) {
require('deasync').sleep(100);
}
var contentBuffer = fs.readFileSync(filename);
var content = contentBuffer + '';
fs.unlinkSync(filename);
return content;
}
};