-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrspack.config.mjs
More file actions
114 lines (108 loc) · 2.55 KB
/
rspack.config.mjs
File metadata and controls
114 lines (108 loc) · 2.55 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
import path from 'path';
import { rspack } from '@rspack/core';
const isProduction = process.env.NODE_ENV === 'production';
const baseConfig = {
entry: {
index: path.join(process.cwd(), 'src/index.ts'),
},
mode: isProduction ? 'production' : 'development',
devtool: isProduction ? false : 'eval-source-map',
resolve: {
extensions: ['.js', '.mjs', '.ts', '.tsx'],
},
module: {
rules: [
{
test: /\.ts(x?)$/,
include: path.join(process.cwd(), 'src'),
use: [
{
loader: 'builtin:swc-loader',
options: {
jsc: {
parser: {
syntax: 'typescript',
},
transform: {
react: {
runtime: 'automatic',
},
},
},
env: {
targets: isProduction ? 'defaults' : 'last 2 versions',
},
},
},
],
},
],
},
optimization: {
usedExports: true, // Enable tree shaking
minimize: isProduction,
mangleExports: false, // Don't mangle export names
nodeEnv: false,
},
experiments: {
rspackFuture: {
bundlerInfo: {
force: false,
},
},
},
externals: isProduction ? {
// Don't bundle peer dependencies in production builds
// Add any peer deps here if needed
} : {},
};
// UMD build (for browser/CDN usage)
const umdConfig = {
...baseConfig,
output: {
filename: 'ecstatic.umd.js',
path: path.resolve(process.cwd(), 'dist'),
library: {
name: 'ecstatic',
type: 'umd',
umdNamedDefine: true,
},
clean: false,
publicPath: '/static/',
},
plugins: isProduction ? [] : [new rspack.HotModuleReplacementPlugin()],
};
// ESM build (for modern bundlers)
const esmConfig = {
...baseConfig,
experiments: {
outputModule: true,
},
output: {
filename: 'ecstatic.esm.js',
path: path.resolve(process.cwd(), 'dist'),
library: {
type: 'module',
},
module: true,
clean: false,
},
externalsType: isProduction ? 'module-import' : undefined,
externals: isProduction ? {
// Externalize dependencies for cleaner ESM output
} : {},
};
// CommonJS build (for Node.js)
const cjsConfig = {
...baseConfig,
output: {
filename: 'ecstatic.cjs.js',
path: path.resolve(process.cwd(), 'dist'),
library: {
type: 'commonjs2',
},
clean: false,
},
};
// export default [umdConfig, esmConfig, cjsConfig];
export default [umdConfig, cjsConfig];