-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
42 lines (33 loc) 路 1 KB
/
index.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
const fs = require('fs');
const path = require('path');
function SymlinkWebpackPlugin (config = []) {
let options;
if (config instanceof Array) {
options = config;
} else {
options = [config];
}
const apply = (compiler) => {
compiler.plugin('after-emit', (compilation, callback) => {
const makeSymlinks = (option) => {
const outputPath = compiler.options.output.path;
const originPath = path.join(outputPath, option.origin);
if (fs.existsSync(originPath)) {
const baseDir = __dirname;
process.chdir(outputPath);
const symlink = path.join(outputPath, option.symlink);
const origin = path.relative(path.dirname(symlink), originPath);
if (fs.existsSync(symlink)) fs.unlinkSync(symlink);
fs.symlinkSync(origin, symlink);
process.chdir(baseDir);
}
};
options.forEach(makeSymlinks);
callback();
});
};
return {
apply
};
}
module.exports = SymlinkWebpackPlugin;