forked from Azure/azure-functions-nodejs-worker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
73 lines (71 loc) · 2.41 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var StringReplacePlugin = require("string-replace-webpack-plugin");
// replace require(expression) with __non_webpack_require__(expression)
var dynamicRequire = {
pattern: /require\(([a-zA-Z0-9_\.]+)\)/,
replacement: function (match, p1, offset, string) {
console.log(`dynamic require ${p1} in ${match}`);
return `__non_webpack_require__(${p1})`;
}
}
module.exports = {
entry: "./dist/src/Worker.js",
output: {
path: `${__dirname}/pkg`,
filename: "worker-bundle.js",
library: "worker",
libraryTarget: "commonjs2"
},
target: 'node',
node: {
__dirname: false
},
externals: [
'memcpy',
],
module: {
loaders: [
{
// supply modified grpc package.json location
test: /.*grpc_extension.js$/,
loader: StringReplacePlugin.replace({
replacements: [
dynamicRequire,
{
pattern: /(\.\.\/)*package.json/,
replacement: function (match, p1, offset, string) {
return "./grpc/package.json";
}
}
]
})
},
{
// supply modified root.pem location
test: /.*grpc.*index.js$/,
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /'\.\.', '\.\.'/,
replacement: function (match, p1, offset, string) {
return `'grpc'`;
}
}
]
})
},
{
// use dynamic require for require(expression)
// versioning.js -> require(env variable)
// pre-binding.js -> require(package_json_path)
// FunctionLoader.js -> require(userFunction)
test: /.*(versioning.js|pre-binding.js|FunctionLoader.js)$/,
loader: StringReplacePlugin.replace({
replacements: [ dynamicRequire ]
})
}
]
},
plugins: [
new StringReplacePlugin()
]
};