-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.ts
79 lines (77 loc) · 2.43 KB
/
webpack.config.ts
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
import path from 'path';
import webpack from 'webpack';
import ESLintPlugin from 'eslint-webpack-plugin';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// import CopyWebpackPlugin from 'copy-webpack-plugin';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import TerserPlugin from 'terser-webpack-plugin';
import nodeExternals from 'webpack-node-externals';
import packageJson from './package.json';
const dir_build = path.resolve(__dirname, "bin");
const configFunction = (env: unknown, argv: {mode: string}) => {
const mode = argv.mode;
return {
mode: mode,
node: {
__dirname: false,
__filename: false
},
// target: "node",
externalsPresets: {node: true},
externals: [nodeExternals()],
entry: {
"main": [
path.resolve(__dirname, "src/commands/main.ts")
]
},
output: {
path: dir_build,
filename: "[name].js",
hashFunction: "sha256"
},
resolve: {
extensions: [".json", ".ts"]
},
module: {
rules: [{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/
}]
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new webpack.IgnorePlugin({resourceRegExp: /^\.\/locale$/, contextRegExp: /moment$/}),
new webpack.BannerPlugin(`HSO D365 CLI ${packageJson.version} | (c) HSO Innovation`),
new ESLintPlugin({
extensions: ['ts', 'tsx'],
}),
].concat(mode === "development" ? [] : [
// new CopyWebpackPlugin({
// patterns:[{
// from: "./root/**/*.json",
// to: dir_build,
// context: "src"
// }]
// }),
]),
stats: {
colors: true
},
optimization: {
minimize: mode === "production",
minimizer: [new TerserPlugin({
extractComments: false,
terserOptions: {
compress: {
drop_console: false, // needed for command line!
}
}
})]
},
devtool: mode === "development" ? "source-map" : false,
}
};
export default configFunction;