-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathwebpack.prod.js
More file actions
118 lines (115 loc) · 3.54 KB
/
webpack.prod.js
File metadata and controls
118 lines (115 loc) · 3.54 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* eslint-disable import/no-extraneous-dependencies */
const path = require('path');
// const fs = require('fs');
const TerserPlugin = require('terser-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const pkg = require('./package.json');
const config = require('./config');
// const nodeModules = {};
// fs.readdirSync('node_modules')
// .filter((x) => {
// return ['.bin'].indexOf(x) === -1;
// })
// .forEach((mod) => {
// nodeModules[mod] = `commonjs ${mod}`;
// });
module.exports = {
mode: 'production',
// entry: path.resolve(__dirname, 'src', 'index.js'),
// Contoh bundle dengan worker thread
entry: {
'server.bundle': path.resolve(__dirname, 'src', 'index.js'),
'buble-sorts.worker': path.resolve(
__dirname,
'src',
'workers',
'buble-sorts.worker.js',
),
'calc-primes.worker': path.resolve(
__dirname,
'src',
'workers',
'calc-primes.worker.js',
),
'workerpool-primes.worker': path.resolve(
__dirname,
'src',
'workers',
'workerpool-primes.worker.js',
),
},
target: 'node',
node: {
// Need this when working with express, otherwise the build fails
__dirname: false, // if you don't put this is, __dirname
__filename: false, // and __filename return blank or /
},
externals: [nodeExternals()],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true,
extractComments: false,
terserOptions: {
mangle: true,
format: {
comments: false,
},
},
}),
],
},
output: {
// filename: 'server.bundle.js',
filename: '[name].js',
path: path.resolve(__dirname, 'bundle', `server-${config.version}`),
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: {
node: pkg.engines.node,
},
},
],
],
plugins: [
[
'@babel/plugin-transform-runtime',
{
regenerator: true,
},
],
'@babel/plugin-proposal-object-rest-spread',
],
},
},
},
],
},
plugins: [
new CopyPlugin({
patterns: [
{ from: 'package.json', to: './' },
{ from: 'package-lock.json', to: './' },
{ from: 'DEPLOY-README.txt', to: './' },
{ from: '.env', to: './' },
{ from: 'winston-logs', to: './winston-logs' },
],
}),
],
resolve: {
modules: ['node_modules'],
extensions: ['.ts', '.js'],
},
};