-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
53 lines (41 loc) · 1.19 KB
/
webpack.config.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
'use strict';
const path = require('path');
const webpack = require('webpack');
const exec = require('child_process').exec;
const destDir = path.resolve(__dirname, 'dist');
const bundleFileName = "node.js";
const destPath = path.join(destDir, bundleFileName);
module.exports = {
mode: 'development',
target: 'node',
devtool: 'original-source',
entry: './entry.js',
output: {
path: destDir,
pathinfo: true,
filename: bundleFileName
},
plugins: [
// just make the output bundle executable via node
new NodeExecPlugin()
]
};
function NodeExecPlugin() {
this.options = {};
}
NodeExecPlugin.prototype.apply = function(compiler) {
compiler.hooks.afterEmit.tap("make-node-exec", () => {
exec(`{ echo '#!/usr/bin/env node'; sed -e '1!b' -e '/function(modules)/!d' ${destPath}; } > ${destPath}.tmp && \
mv ${destPath}.tmp ${destPath} && \
chmod u+x ${destPath} && \
echo 'Successfully created node executable at ${destPath}.'`,
function(error, stdout, stderr){
if(error){
console.log(error, stderr);
}
else{
console.log(stdout);
}
});
});
};