-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
60 lines (50 loc) · 1.89 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const compile = require('./compile');
const link = require('./link');
const Through = require('through2');
const Path = require('path');
module.exports = function({ cacheDir, compilers, extensions, linkExtensions, outDir }) {
return function({ module, entry, context, target = 'web' }) {
let compileCache = null;
context = context || Path.dirname(entry);
compileCache = Path.resolve(cacheDir, `./${Path.basename(context)}`);
const startCompileProcess = function(linkParalel = false) {
let compilerConfig = {
output: compileCache,
moduleName: module,
entryFile: entry,
compilerList: compilers,
extensions: extensions,
context: context,
};
let linkerConfig = {
context: Path.resolve(compileCache),
entry: { [module]: Path.resolve(compileCache, Path.relative(context, Path.resolve(entry))) },
devtool: 'source-map',
target: target,
paralelLinking: linkParalel,
output: {
pathinfo: true,
path: Path.resolve(outDir),
filename: '[name].js',
},
resolve: {
extensions: linkExtensions || extensions,
},
};
compile(compilerConfig);
return link(linkerConfig);
};
if (entry) {
return startCompileProcess();
} else {
return Through.obj(function (file, encoding, callback) {
entry = file.path;
startCompileProcess(true)
.then(callback)
.catch(() => callback(new Error('Compilation Failed!')));
this.push(file);
return true;
});
}
};
};