@jpp-toolkit/rspack-config 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +48 -12
- package/dist/index.mjs +331 -120
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -2
- package/src/constants.ts +4 -0
- package/src/create-rspack-config.ts +136 -0
- package/src/index.ts +2 -1
- package/src/presets/base-preset.ts +114 -0
- package/src/presets/fivem-script-preset.ts +27 -0
- package/src/presets/fivem-ui-preset.ts +41 -0
- package/src/presets/index.ts +5 -0
- package/src/presets/node-preset.ts +65 -0
- package/src/presets/react-preset.ts +139 -0
- package/src/types/index.ts +3 -0
- package/src/types/preset.ts +13 -0
- package/src/types/rspack-env.ts +6 -0
- package/src/types/run-context.ts +8 -0
- package/src/utils/find-first-existing-file.ts +7 -0
- package/src/utils/merge-config.ts +14 -0
- package/src/create-fivem-rspack-config.ts +0 -166
- package/src/enums/environment.ts +0 -5
- package/src/enums/fivem-entry-type.ts +0 -7
- package/src/enums/index.ts +0 -2
- package/src/utils/find-first-existing-path.ts +0 -6
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import { rspack } from '@rspack/core';
|
|
4
|
-
import type { RspackOptions } from '@rspack/core';
|
|
5
|
-
|
|
6
|
-
import { Environment, FivemEntryType } from './enums';
|
|
7
|
-
import { findFirstExistingPath } from './utils/find-first-existing-path';
|
|
8
|
-
|
|
9
|
-
type BuildConfigOptions = {
|
|
10
|
-
readonly cwd: string;
|
|
11
|
-
readonly entry: string;
|
|
12
|
-
readonly entryType: FivemEntryType;
|
|
13
|
-
readonly resourceName: string;
|
|
14
|
-
readonly environment: Environment;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
function buildConfig(options: BuildConfigOptions): RspackOptions {
|
|
18
|
-
const { cwd, entry, entryType, resourceName, environment } = options;
|
|
19
|
-
|
|
20
|
-
const htmlTemplateFile = findFirstExistingPath([
|
|
21
|
-
path.resolve(cwd, `src/${entryType}/index.html`),
|
|
22
|
-
path.resolve(cwd, `src/${entryType}.html`),
|
|
23
|
-
]);
|
|
24
|
-
const publicPath = `https://cfx-nui-${resourceName}/dist/${entryType}/`;
|
|
25
|
-
|
|
26
|
-
const isProduction = environment === 'production';
|
|
27
|
-
const isUi = entryType === FivemEntryType.UI;
|
|
28
|
-
|
|
29
|
-
const config: RspackOptions = {
|
|
30
|
-
name: `fivem-${entryType}`,
|
|
31
|
-
|
|
32
|
-
context: cwd,
|
|
33
|
-
|
|
34
|
-
target: isUi ? 'web' : 'node16',
|
|
35
|
-
devtool: false,
|
|
36
|
-
mode: environment,
|
|
37
|
-
|
|
38
|
-
entry,
|
|
39
|
-
|
|
40
|
-
output: {
|
|
41
|
-
clean: true,
|
|
42
|
-
path: path.resolve(cwd, 'dist', entryType),
|
|
43
|
-
...(isUi ? { publicPath } : {}),
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
optimization: {
|
|
47
|
-
minimize: isProduction,
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
resolve: {
|
|
51
|
-
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json', '.wasm'],
|
|
52
|
-
extensionAlias: {
|
|
53
|
-
'.js': ['.ts', '.js'],
|
|
54
|
-
'.cjs': ['.cts', '.cjs'],
|
|
55
|
-
'.mjs': ['.mts', '.mjs'],
|
|
56
|
-
},
|
|
57
|
-
tsConfig: path.resolve(cwd, 'tsconfig.json'),
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
node: {
|
|
61
|
-
global: isUi,
|
|
62
|
-
__filename: isUi,
|
|
63
|
-
__dirname: isUi,
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
externalsPresets: {
|
|
67
|
-
node: !isUi,
|
|
68
|
-
web: isUi,
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
module: {
|
|
72
|
-
rules: [
|
|
73
|
-
{
|
|
74
|
-
test: /\.(?:ts|tsx|cts|mts)$/iu,
|
|
75
|
-
type: 'javascript/auto',
|
|
76
|
-
exclude: [/dist\//u, /node_modules\//u],
|
|
77
|
-
loader: 'builtin:swc-loader',
|
|
78
|
-
options: {
|
|
79
|
-
minify: isProduction,
|
|
80
|
-
module: { type: 'nodenext' },
|
|
81
|
-
jsc: {
|
|
82
|
-
target: isUi ? 'es5' : 'es2021',
|
|
83
|
-
parser: {
|
|
84
|
-
syntax: 'typescript',
|
|
85
|
-
tsx: true,
|
|
86
|
-
},
|
|
87
|
-
transform: {
|
|
88
|
-
react: { runtime: 'automatic' },
|
|
89
|
-
useDefineForClassFields: true,
|
|
90
|
-
},
|
|
91
|
-
keepClassNames: true,
|
|
92
|
-
externalHelpers: false,
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
...(isUi ?
|
|
97
|
-
[
|
|
98
|
-
{
|
|
99
|
-
test: /\.(?:jpe?g|png|gif|svg)$/iu,
|
|
100
|
-
type: 'asset/resource',
|
|
101
|
-
},
|
|
102
|
-
]
|
|
103
|
-
: []),
|
|
104
|
-
],
|
|
105
|
-
},
|
|
106
|
-
|
|
107
|
-
...(isUi ? { experiments: { css: true } } : {}),
|
|
108
|
-
|
|
109
|
-
...(isUi && htmlTemplateFile ?
|
|
110
|
-
{ plugins: [new rspack.HtmlRspackPlugin({ template: htmlTemplateFile, publicPath })] }
|
|
111
|
-
: {}),
|
|
112
|
-
|
|
113
|
-
watchOptions: {
|
|
114
|
-
aggregateTimeout: 200,
|
|
115
|
-
ignored: [
|
|
116
|
-
'**/.git',
|
|
117
|
-
'**/.turbo',
|
|
118
|
-
'**/coverage',
|
|
119
|
-
'**/dist',
|
|
120
|
-
'**/generated',
|
|
121
|
-
'**/old',
|
|
122
|
-
'**/tmp',
|
|
123
|
-
],
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
return config;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export type CreateFivemRspackConfigOptions = {
|
|
131
|
-
readonly resourceName?: string | undefined;
|
|
132
|
-
readonly environment?: Environment | undefined;
|
|
133
|
-
readonly cwd?: string | undefined;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
export function createFivemRspackConfig(
|
|
137
|
-
options: CreateFivemRspackConfigOptions = {},
|
|
138
|
-
): RspackOptions[] {
|
|
139
|
-
const environment =
|
|
140
|
-
options.environment
|
|
141
|
-
?? (process.env.NODE_ENV === Environment.PRODUCTION ?
|
|
142
|
-
Environment.PRODUCTION
|
|
143
|
-
: Environment.DEVELOPMENT);
|
|
144
|
-
const cwd = options.cwd ?? process.cwd();
|
|
145
|
-
const resourceName = options.resourceName ?? path.basename(cwd);
|
|
146
|
-
|
|
147
|
-
const configs: RspackOptions[] = [];
|
|
148
|
-
|
|
149
|
-
for (const entryType of Object.values(FivemEntryType)) {
|
|
150
|
-
const entry = findFirstExistingPath([
|
|
151
|
-
path.resolve(cwd, `src/${entryType}/index.tsx`),
|
|
152
|
-
path.resolve(cwd, `src/${entryType}/index.ts`),
|
|
153
|
-
path.resolve(cwd, `src/${entryType}.tsx`),
|
|
154
|
-
path.resolve(cwd, `src/${entryType}.ts`),
|
|
155
|
-
]);
|
|
156
|
-
|
|
157
|
-
if (!entry) continue;
|
|
158
|
-
|
|
159
|
-
const config = buildConfig({ cwd, entry, entryType, environment, resourceName });
|
|
160
|
-
configs.push(config);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (configs.length === 0) throw new Error('No valid FiveM resource entries found.');
|
|
164
|
-
|
|
165
|
-
return configs;
|
|
166
|
-
}
|
package/src/enums/environment.ts
DELETED
package/src/enums/index.ts
DELETED