-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.config.js
More file actions
135 lines (132 loc) · 3.48 KB
/
webpack.config.js
File metadata and controls
135 lines (132 loc) · 3.48 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const path = require('node:path');
const webpack = require('webpack');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const isProduction = process.env.NODE_ENV === 'production';
const analyze = process.env.ANALYZE === 'true';
const baseConfig = {
mode: isProduction ? 'production' : 'development',
target: 'node',
externals: {
// Keep Node.js built-ins external
fs: 'commonjs fs',
path: 'commonjs path',
crypto: 'commonjs crypto',
util: 'commonjs util',
events: 'commonjs events',
stream: 'commonjs stream',
zlib: 'commonjs zlib',
child_process: 'commonjs child_process',
os: 'commonjs os',
url: 'commonjs url',
http: 'commonjs http',
https: 'commonjs https',
buffer: 'commonjs buffer',
// Keep large dependencies external to reduce bundle size
zod: 'commonjs zod',
commander: 'commonjs commander',
'ts-morph': 'commonjs ts-morph',
'@faker-js/faker': 'commonjs @faker-js/faker',
'fast-glob': 'commonjs fast-glob',
chokidar: 'commonjs chokidar',
ws: 'commonjs ws',
ink: 'commonjs ink',
react: 'commonjs react',
'ink-spinner': 'commonjs ink-spinner',
'ink-select-input': 'commonjs ink-select-input',
'ink-text-input': 'commonjs ink-text-input',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
alias: {
'@': path.resolve(__dirname, 'src'),
'@core': path.resolve(__dirname, 'src/core'),
'@cli': path.resolve(__dirname, 'src/cli'),
'@utils': path.resolve(__dirname, 'src/utils'),
},
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
use: [
{
loader: 'ts-loader',
options: {
configFile: path.resolve(__dirname, 'tsconfig.json'),
transpileOnly: !isProduction, // Faster builds in dev
compilerOptions: {
// Override for webpack build
module: 'ESNext',
target: 'ES2020',
moduleResolution: 'node',
allowSyntheticDefaultImports: true,
esModuleInterop: true,
},
},
},
],
exclude: /node_modules/,
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
__VERSION__: JSON.stringify(require('./package.json').version),
__DEV__: JSON.stringify(!isProduction),
}),
// Tree shaking optimization
new webpack.optimize.ModuleConcatenationPlugin(),
...(analyze ? [new BundleAnalyzerPlugin()] : []),
],
optimization: {
minimize: isProduction,
usedExports: true, // Enable tree shaking
sideEffects: false, // Enable aggressive tree shaking
// Disable split chunks for CLI to avoid conflicts
splitChunks: false,
},
performance: {
maxAssetSize: 250000, // 250KB
maxEntrypointSize: 250000,
hints: isProduction ? 'error' : 'warning',
},
};
module.exports = [
// CLI Entry Point - Minimal for debugging
{
...baseConfig,
name: 'cli',
entry: './src/cli/functional.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'cli/index.js',
clean: true,
libraryTarget: 'commonjs2',
},
plugins: [
...baseConfig.plugins,
new webpack.BannerPlugin({
banner: '#!/usr/bin/env node',
raw: true,
}),
],
},
// Library Entry Point
{
...baseConfig,
name: 'lib',
entry: './src/index.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'index.js',
libraryTarget: 'commonjs2',
library: 'zodkit',
},
optimization: {
...baseConfig.optimization,
// More aggressive optimization for library
splitChunks: false, // Single bundle for library
},
},
];