-
Notifications
You must be signed in to change notification settings - Fork 351
/
build-worker.js
34 lines (28 loc) · 946 Bytes
/
build-worker.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
let path = require('path');
let fs = require('fs');
let workerPath = './dist/worker.min.js';
let outputPath = '';
if (process.env.NODE_ENV == 'compress') {
outputPath = './dist/inmap.min.js';
} else {
outputPath = './dist/inmap.js';
}
let workerContent = fs.readFileSync(path.join(__dirname, workerPath), 'utf-8');
fs.readFile(path.join(__dirname, outputPath), 'utf-8', function (err, data) {
if (err) {
throw new Error('file not find');
} else {
workerContent = workerContent.replace(/"/g, '\\"').replace(/'/g, '\\\'');
let repaleData = data.replace('[workerContentString]', workerContent);
fs.writeFile(path.join(__dirname, outputPath), repaleData, function (err) {
if (err) {
throw new Error('write error');
}
});
}
});
if (process.env.NODE_ENV !== 'compress') {
fs.unlink(workerPath, (err) => {
if (err) throw err;
});
}