-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompiler.js
45 lines (39 loc) · 945 Bytes
/
compiler.js
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
40
41
42
43
44
45
const MemoryFs = require('memory-fs')
const webpack = require('webpack')
function compile(scriptPath) {
const compiler = webpack({
output: {
filename: 'bundle.js',
path: '/'
},
mode: 'development',
entry: scriptPath,
target: 'es6',
devtool: 'eval',
module: {
rules: [
{
test: /\.(png|jpe?g|gif|wasm)$/i,
use: ['@scytheapp/arraybuffer-loader']
}
]
}
})
compiler.outputFileSystem = new MemoryFs()
return new Promise((resolve, reject) => {
compiler.run((err, stats) => {
if (err) return reject(err)
if (stats.hasErrors() || stats.hasWarnings()) {
return reject(new Error(stats.toString({
errorDetails: false,
warnings: true
})))
}
const result = compiler.outputFileSystem.data['bundle.js'].toString()
resolve({ result, stats })
})
})
}
module.exports = {
compile
}