-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
110 lines (103 loc) · 2.63 KB
/
webpack.config.js
File metadata and controls
110 lines (103 loc) · 2.63 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
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require("path");
const TerserPlugin = require("terser-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
const glob = require('glob')
function separatePaths(pattern) {
const filesArr = glob.sync(pattern);
return filesArr.reduce((acc, file) => {
const entryName = path.relative('./src', file).replace(/\.[^/.]+$/, '');
acc[entryName] = path.resolve(__dirname, file);
return acc;
}, {});
}
const migrationEntries = separatePaths("./src/db/sequelize/migrations/*")
const seederEntries = separatePaths("./src/db/sequelize/seeders/*")
module.exports = {
target: "node",
mode: "production",
entry: {
index: "./src/index.ts",
config: "./src/db/sequelize/config/config.js",
...migrationEntries,
...seederEntries,
},
output: {
libraryTarget: 'commonjs',
path: path.resolve(__dirname, 'dist'),
filename: chunkData => {
const name = chunkData.chunk.name
if (Object.keys(migrationEntries).includes(name)) {
return `migrations/${path.basename(name)}.js`;
}
if (Object.keys(seederEntries).includes(name)) {
return `seeders/${path.basename(name)}.js`;
}
if (name === 'config') {
return 'config/config.js';
}
return '[name].js';
},
clean: true,
},
resolve: {
extensions: [".ts", ".js"],
plugins: [
new TsconfigPathsPlugin({ configFile: "./tsconfig.json" }),
],
},
plugins: [
new webpack.DefinePlugin({
'process.env': 'process.env',
}),
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [
{ from: ".sequelizerc", to: "." },
{ from: "package.json", to: '.' },
],
}),
],
externals: [nodeExternals()],
module: {
rules: [
{
test: /\.ts$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.node$/,
use: "node-loader",
},
],
},
optimization: {
minimize: true,
nodeEnv: false,
minimizer: [
new TerserPlugin({
terserOptions: {
format: {
comments: false,
},
},
extractComments: false,
}),
],
splitChunks: {
cacheGroups: {
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
},
},
},
},
devtool: false,
};