-
Notifications
You must be signed in to change notification settings - Fork 120
/
webpack.config.server.worker.development.js
85 lines (81 loc) · 2.36 KB
/
webpack.config.server.worker.development.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
74
75
76
77
78
79
80
81
82
83
84
85
/* eslint no-var: 0 */
/* eslint prefer-arrow-callback: 0 */
const crypto = require('crypto');
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const babelConfig = require('./babel.config');
const pkg = require('./package.json');
const NODE_MODULES = path.resolve(__dirname, 'node_modules');
// http://jlongster.com/Backend-Apps-with-Webpack--Part-I
const externals = {};
fs.readdirSync(NODE_MODULES)
.filter((x) => {
return ['.bin'].indexOf(x) === -1;
})
.forEach((mod) => {
externals[mod] = `commonjs ${mod}`;
});
externals['@snapmaker/snapmaker-lunar'] = 'commonjs @snapmaker/snapmaker-lunar';
// Use publicPath for production
const publicPath = (function calculatePublicPath(payload) {
const algorithm = 'sha1';
const buf = String(payload);
const hash = crypto.createHash(algorithm).update(buf).digest('hex');
return `/${hash.substr(0, 8)}/`; // 8 digits
}(pkg.version));
module.exports = {
mode: 'development',
devtool: 'eval-source-map',
target: 'node',
watch: true,
context: path.resolve(__dirname, './src/server'),
entry: path.resolve(__dirname, './src/server/services/task-manager/Pool.worker.js'),
output: {
path: path.resolve(__dirname, 'output/src/server'),
filename: '[name].js',
libraryTarget: 'commonjs2'
},
plugins: [
new webpack.DefinePlugin({
'global.PUBLIC_PATH': JSON.stringify(publicPath)
})
],
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader'
},
{
test: /\.worker\.(j|t)s$/,
loader: 'worker-loader',
options: {
filename: '[name].js',
},
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: babelConfig
}
]
},
externals: externals,
resolve: {
extensions: ['.js', '.json', '.jsx', '.ts']
},
resolveLoader: {
modules: [NODE_MODULES]
},
node: {
console: true,
global: true,
process: true,
Buffer: true,
__filename: true, // Use relative path
__dirname: true, // Use relative path
setImmediate: true
}
};