-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
356 lines (319 loc) · 8.85 KB
/
webpack.config.js
File metadata and controls
356 lines (319 loc) · 8.85 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/**
* Claude Code Webpack Configuration
*
* Build configuration for bundling Claude Code CLI.
* Handles development and production builds with optimization.
*
* Part of the 98% → 100% extraction phase
*/
const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
module.exports = (env, argv) => {
const isDevelopment = argv.mode === 'development';
const isProduction = argv.mode === 'production';
const isAnalyze = process.env.ANALYZE === 'true';
return {
// Entry points
entry: {
main: './src/index.js',
cli: './src/cli/cli-entry.js',
runtime: './src/runtime/runtime-initialization.js'
},
// Output configuration
output: {
path: path.resolve(__dirname, 'dist'),
filename: isProduction ? '[name].[contenthash:8].js' : '[name].js',
chunkFilename: isProduction ? '[name].[contenthash:8].chunk.js' : '[name].chunk.js',
library: 'ClaudeCode',
libraryTarget: 'commonjs2',
clean: true
},
// Target Node.js
target: 'node',
// Node polyfills
node: {
__dirname: false,
__filename: false,
global: true
},
// Mode
mode: isDevelopment ? 'development' : 'production',
// Source maps
devtool: isDevelopment ? 'eval-source-map' : 'source-map',
// Module resolution
resolve: {
extensions: ['.js', '.json', '.node'],
alias: {
'@': path.resolve(__dirname, 'src'),
'@tools': path.resolve(__dirname, 'src/tools'),
'@utils': path.resolve(__dirname, 'src/utils'),
'@api': path.resolve(__dirname, 'src/api'),
'@ui': path.resolve(__dirname, 'src/ui'),
'@config': path.resolve(__dirname, 'src/config'),
'@runtime': path.resolve(__dirname, 'src/runtime')
},
fallback: {
// Node.js core modules
fs: false,
path: false,
os: false,
crypto: false,
stream: false,
http: false,
https: false,
zlib: false,
util: false,
buffer: false,
events: false,
child_process: false
}
},
// Module rules
module: {
rules: [
// JavaScript
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', {
targets: { node: '18' },
modules: false
}]
],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-nullish-coalescing-operator',
'@babel/plugin-transform-runtime'
]
}
}
},
// JSON
{
test: /\.json$/,
type: 'json'
},
// Native modules
{
test: /\.node$/,
use: 'node-loader'
}
]
},
// Plugins
plugins: [
// Define environment variables
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(argv.mode),
'process.env.VERSION': JSON.stringify(require('./package.json').version),
'process.env.BUILD_TIME': JSON.stringify(new Date().toISOString())
}),
// Banner plugin
new webpack.BannerPlugin({
banner: '#!/usr/bin/env node',
raw: true,
entryOnly: true,
include: /cli/
}),
// Progress plugin
new webpack.ProgressPlugin({
activeModules: true,
entries: true,
modules: true,
modulesCount: 100,
profile: false,
dependencies: true,
dependenciesCount: 10000,
percentBy: 'entries'
}),
// Ignore moment locales
new webpack.IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/
}),
// Compression in production
...(isProduction ? [
new CompressionPlugin({
algorithm: 'gzip',
test: /\.(js|json)$/,
threshold: 10240,
minRatio: 0.8
})
] : []),
// Bundle analyzer
...(isAnalyze ? [
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: 'bundle-report.html',
openAnalyzer: false
})
] : [])
],
// Optimization
optimization: {
minimize: isProduction,
minimizer: [
new TerserPlugin({
terserOptions: {
parse: {
ecma: 2020
},
compress: {
ecma: 2020,
warnings: false,
comparisons: false,
inline: 2,
drop_console: isProduction,
drop_debugger: true,
pure_funcs: isProduction ? ['console.log', 'console.debug'] : []
},
mangle: {
safari10: true
},
output: {
ecma: 2020,
comments: false,
ascii_only: true
}
},
parallel: true,
extractComments: false
})
],
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
// Vendor chunks
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
priority: 10,
reuseExistingChunk: true
},
// Common chunks
common: {
minChunks: 2,
priority: 5,
reuseExistingChunk: true
},
// Tool chunks
tools: {
test: /[\\/]src[\\/]tools[\\/]/,
name: 'tools',
priority: 8,
reuseExistingChunk: true
},
// UI chunks
ui: {
test: /[\\/]src[\\/]ui[\\/]/,
name: 'ui',
priority: 7,
reuseExistingChunk: true
},
// Utils chunks
utils: {
test: /[\\/]src[\\/]utils[\\/]/,
name: 'utils',
priority: 6,
reuseExistingChunk: true
}
}
},
// Module concatenation
concatenateModules: true,
// Side effects
sideEffects: false,
// Used exports
usedExports: true,
// Provide exports
providedExports: true
},
// Performance hints
performance: {
hints: isProduction ? 'warning' : false,
maxEntrypointSize: 5000000,
maxAssetSize: 5000000
},
// Stats
stats: {
colors: true,
modules: false,
children: false,
chunks: false,
chunkModules: false,
entrypoints: true,
env: true,
errors: true,
errorDetails: true,
warnings: true,
publicPath: true,
timings: true,
version: true,
hash: true
},
// Externals - Don't bundle these
externals: {
// Native modules
'node:fs': 'commonjs2 fs',
'node:path': 'commonjs2 path',
'node:os': 'commonjs2 os',
'node:crypto': 'commonjs2 crypto',
'node:stream': 'commonjs2 stream',
'node:child_process': 'commonjs2 child_process',
'node:http': 'commonjs2 http',
'node:https': 'commonjs2 https',
'node:zlib': 'commonjs2 zlib',
'node:util': 'commonjs2 util',
'node:buffer': 'commonjs2 buffer',
'node:events': 'commonjs2 events',
'node:url': 'commonjs2 url',
'node:querystring': 'commonjs2 querystring',
'node:net': 'commonjs2 net',
'node:tls': 'commonjs2 tls',
'node:cluster': 'commonjs2 cluster',
'node:process': 'commonjs2 process',
'node:v8': 'commonjs2 v8',
'node:vm': 'commonjs2 vm',
'node:worker_threads': 'commonjs2 worker_threads',
'node:perf_hooks': 'commonjs2 perf_hooks',
// Optional native dependencies
'keytar': 'commonjs2 keytar',
'electron': 'commonjs2 electron',
'fsevents': 'commonjs2 fsevents',
'bufferutil': 'commonjs2 bufferutil',
'utf-8-validate': 'commonjs2 utf-8-validate'
},
// Watch options
watchOptions: {
ignored: /node_modules/,
aggregateTimeout: 300,
poll: 1000
},
// Cache
cache: {
type: 'filesystem',
cacheDirectory: path.resolve(__dirname, '.cache'),
buildDependencies: {
config: [__filename]
}
},
// Infrastructure logging
infrastructureLogging: {
level: 'warn'
}
};
};
// Export helper functions
module.exports.createDevelopmentConfig = () => module.exports(null, { mode: 'development' });
module.exports.createProductionConfig = () => module.exports(null, { mode: 'production' });