-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.common.js
99 lines (97 loc) · 2.37 KB
/
webpack.common.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const path = require("path");
const dotenv = require("dotenv");
const webpack = require("webpack");
const CopyPlugin = require("copy-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const LicenseWebpackPlugin = require("license-webpack-plugin")
.LicenseWebpackPlugin;
const env = dotenv.config().parsed;
const envKeys = Object.keys(env).reduce((prev, next) => {
prev[`process.env.${next}`] = JSON.stringify(env[next]);
return prev;
}, {});
/** @type { import('webpack').Configuration } */
module.exports = {
target: "node",
entry: {
cloud: path.join(__dirname, "src/cloud/main.ts"),
},
output: {
path: path.join(__dirname, "dist"),
filename: "[name].js",
hashFunction: "sha512",
},
module: {
rules: [
{
exclude: /node_modules/,
test: /\.tsx?$/,
use: "babel-loader",
},
{
exclude: /node_modules/,
test: /\.js?$/,
use: "babel-loader",
},
{
test: /\.node?$/,
use: "file-loader",
type: "javascript/auto",
},
],
},
plugins: [
new LicenseWebpackPlugin(),
new webpack.DefinePlugin(envKeys),
new webpack.IgnorePlugin({ resourceRegExp: /^pg-native$/ }),
new CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, "index.js"),
to: path.resolve(__dirname, "dist", "index.js"),
},
{
from: path.resolve(__dirname, ".env"),
to: path.resolve(__dirname, "dist", ".env"),
toType: "file",
},
{
from: path.resolve(__dirname, "firebase-service-account-key.json"),
to: path.resolve(
__dirname,
"dist",
"firebase-service-account-key.json"
),
},
],
}),
],
resolve: {
plugins: [new TsconfigPathsPlugin()],
extensions: [".ts", ".tsx", ".js", ".json"],
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
format: {
comments: false,
},
},
extractComments: false,
}),
],
},
node: {
// child_process: "empty",
// fs: "empty",
// crypto: "empty",
// net: "empty",
// tls: "empty",
__dirname: false,
__filename: false,
},
};