@jpp-toolkit/rspack-config 0.0.2

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Julien Papini
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,10 @@
1
+ import { RspackOptions } from "@rspack/core";
2
+
3
+ //#region src/create-fivem-rspack-config.d.ts
4
+ declare function createFivemRspackConfig(overrides?: RspackOptions): RspackOptions;
5
+ //#endregion
6
+ //#region src/utils/merge-config.d.ts
7
+ declare const mergeConfig: (firstConfiguration: object | object[], ...configurations: object[]) => object;
8
+ //#endregion
9
+ export { createFivemRspackConfig, mergeConfig };
10
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,85 @@
1
+ import path from "node:path";
2
+ import { mergeWithRules } from "webpack-merge";
3
+
4
+ //#region src/utils/merge-config.ts
5
+ const mergeConfig = mergeWithRules({ module: { rules: {
6
+ test: "match",
7
+ use: {
8
+ loader: "match",
9
+ options: "merge"
10
+ }
11
+ } } });
12
+
13
+ //#endregion
14
+ //#region src/create-fivem-rspack-config.ts
15
+ function createFivemRspackConfig(overrides = {}) {
16
+ const cwd = overrides.context ?? process.cwd();
17
+ const mode = overrides.mode ?? (process.env.NODE_ENV === "production" ? "production" : "development");
18
+ const isProduction = mode === "production";
19
+ return mergeConfig({
20
+ name: "fivem",
21
+ context: cwd,
22
+ target: "node16",
23
+ devtool: false,
24
+ mode,
25
+ entry: path.resolve(cwd, "src/index.ts"),
26
+ output: {
27
+ clean: true,
28
+ path: path.resolve(cwd, "dist")
29
+ },
30
+ optimization: { minimize: isProduction },
31
+ resolve: {
32
+ extensions: [
33
+ ".js",
34
+ ".json",
35
+ ".wasm",
36
+ ".ts"
37
+ ],
38
+ extensionAlias: {
39
+ ".js": [".ts", ".js"],
40
+ ".cjs": [".cts", ".cjs"],
41
+ ".mjs": [".mts", ".mjs"]
42
+ },
43
+ tsConfig: path.resolve(cwd, "tsconfig.json")
44
+ },
45
+ node: {
46
+ global: false,
47
+ __filename: false,
48
+ __dirname: false
49
+ },
50
+ externalsPresets: { node: true },
51
+ module: { rules: [{
52
+ test: /\.(?:ts|cts|mts)$/iu,
53
+ type: "javascript/auto",
54
+ exclude: [/dist\//u, /node_modules\//u],
55
+ loader: "builtin:swc-loader",
56
+ options: {
57
+ minify: isProduction,
58
+ module: { type: "nodenext" },
59
+ jsc: {
60
+ target: "es2021",
61
+ parser: { syntax: "typescript" },
62
+ transform: { useDefineForClassFields: true },
63
+ keepClassNames: true,
64
+ externalHelpers: false
65
+ }
66
+ }
67
+ }] },
68
+ watchOptions: {
69
+ aggregateTimeout: 200,
70
+ ignored: [
71
+ "**/.git",
72
+ "**/.turbo",
73
+ "**/coverage",
74
+ "**/dist",
75
+ "**/generated",
76
+ "**/old",
77
+ "**/tmp"
78
+ ]
79
+ }
80
+ }, overrides);
81
+ }
82
+
83
+ //#endregion
84
+ export { createFivemRspackConfig, mergeConfig };
85
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/utils/merge-config.ts","../src/create-fivem-rspack-config.ts"],"sourcesContent":["import { mergeWithRules } from 'webpack-merge';\n\nexport const mergeConfig = mergeWithRules({\n module: {\n rules: {\n test: 'match',\n use: {\n loader: 'match',\n options: 'merge',\n },\n },\n },\n});\n","import path from 'node:path';\n\nimport type { RspackOptions } from '@rspack/core';\n\nimport { mergeConfig } from './utils/merge-config';\n\nexport function createFivemRspackConfig(overrides: RspackOptions = {}): RspackOptions {\n const cwd = overrides.context ?? process.cwd();\n const mode =\n overrides.mode ?? (process.env.NODE_ENV === 'production' ? 'production' : 'development');\n const isProduction = mode === 'production';\n\n const config: RspackOptions = {\n name: 'fivem',\n\n context: cwd,\n\n target: 'node16',\n devtool: false,\n mode,\n\n entry: path.resolve(cwd, 'src/index.ts'),\n\n output: {\n clean: true,\n path: path.resolve(cwd, 'dist'),\n },\n\n optimization: {\n minimize: isProduction,\n },\n\n resolve: {\n extensions: ['.js', '.json', '.wasm', '.ts'],\n extensionAlias: {\n '.js': ['.ts', '.js'],\n '.cjs': ['.cts', '.cjs'],\n '.mjs': ['.mts', '.mjs'],\n },\n tsConfig: path.resolve(cwd, 'tsconfig.json'),\n },\n\n node: {\n global: false,\n __filename: false,\n __dirname: false,\n },\n\n externalsPresets: {\n node: true,\n },\n\n module: {\n rules: [\n {\n test: /\\.(?:ts|cts|mts)$/iu,\n type: 'javascript/auto',\n exclude: [/dist\\//u, /node_modules\\//u],\n loader: 'builtin:swc-loader',\n options: {\n minify: isProduction,\n module: {\n type: 'nodenext',\n },\n jsc: {\n target: 'es2021',\n parser: {\n syntax: 'typescript',\n },\n transform: {\n useDefineForClassFields: true,\n },\n keepClassNames: true,\n externalHelpers: false,\n },\n },\n },\n ],\n },\n\n watchOptions: {\n aggregateTimeout: 200,\n ignored: [\n '**/.git',\n '**/.turbo',\n '**/coverage',\n '**/dist',\n '**/generated',\n '**/old',\n '**/tmp',\n ],\n },\n };\n\n return mergeConfig(config, overrides);\n}\n"],"mappings":";;;;AAEA,MAAa,cAAc,eAAe,EACtC,QAAQ,EACJ,OAAO;CACH,MAAM;CACN,KAAK;EACD,QAAQ;EACR,SAAS;EACZ;CACJ,EACJ,EACJ,CAAC;;;;ACNF,SAAgB,wBAAwB,YAA2B,EAAE,EAAiB;CAClF,MAAM,MAAM,UAAU,WAAW,QAAQ,KAAK;CAC9C,MAAM,OACF,UAAU,SAAS,QAAQ,IAAI,aAAa,eAAe,eAAe;CAC9E,MAAM,eAAe,SAAS;AAoF9B,QAAO,YAlFuB;EAC1B,MAAM;EAEN,SAAS;EAET,QAAQ;EACR,SAAS;EACT;EAEA,OAAO,KAAK,QAAQ,KAAK,eAAe;EAExC,QAAQ;GACJ,OAAO;GACP,MAAM,KAAK,QAAQ,KAAK,OAAO;GAClC;EAED,cAAc,EACV,UAAU,cACb;EAED,SAAS;GACL,YAAY;IAAC;IAAO;IAAS;IAAS;IAAM;GAC5C,gBAAgB;IACZ,OAAO,CAAC,OAAO,MAAM;IACrB,QAAQ,CAAC,QAAQ,OAAO;IACxB,QAAQ,CAAC,QAAQ,OAAO;IAC3B;GACD,UAAU,KAAK,QAAQ,KAAK,gBAAgB;GAC/C;EAED,MAAM;GACF,QAAQ;GACR,YAAY;GACZ,WAAW;GACd;EAED,kBAAkB,EACd,MAAM,MACT;EAED,QAAQ,EACJ,OAAO,CACH;GACI,MAAM;GACN,MAAM;GACN,SAAS,CAAC,WAAW,kBAAkB;GACvC,QAAQ;GACR,SAAS;IACL,QAAQ;IACR,QAAQ,EACJ,MAAM,YACT;IACD,KAAK;KACD,QAAQ;KACR,QAAQ,EACJ,QAAQ,cACX;KACD,WAAW,EACP,yBAAyB,MAC5B;KACD,gBAAgB;KAChB,iBAAiB;KACpB;IACJ;GACJ,CACJ,EACJ;EAED,cAAc;GACV,kBAAkB;GAClB,SAAS;IACL;IACA;IACA;IACA;IACA;IACA;IACA;IACH;GACJ;EACJ,EAE0B,UAAU"}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@jpp-toolkit/rspack-config",
3
+ "version": "0.0.2",
4
+ "description": "Rspack configurations for JS/TS projects.",
5
+ "keywords": [
6
+ "jpp",
7
+ "rspack",
8
+ "config"
9
+ ],
10
+ "homepage": "https://github.com/jpapini/jpp-toolkit/tree/main/packages/rspack-config#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/jpapini/jpp-toolkit/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/jpapini/jpp-toolkit.git",
17
+ "directory": "packages/rspack-config"
18
+ },
19
+ "license": "MIT",
20
+ "author": "Julien Papini <julien.papini@gmail.com> (https://github.com/jpapini)",
21
+ "type": "module",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.mts",
25
+ "default": "./dist/index.mjs"
26
+ },
27
+ "./package.json": "./package.json"
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "src"
32
+ ],
33
+ "dependencies": {
34
+ "webpack-merge": "6.0.1"
35
+ },
36
+ "devDependencies": {
37
+ "@rspack/core": "1.6.7"
38
+ },
39
+ "engines": {
40
+ "node": "24",
41
+ "pnpm": "10"
42
+ },
43
+ "volta": {
44
+ "extends": "../../package.json"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "scripts": {
50
+ "typecheck": "tsc --noEmit --pretty",
51
+ "dev": "build-lib --watch",
52
+ "build": "build-lib"
53
+ }
54
+ }
@@ -0,0 +1,96 @@
1
+ import path from 'node:path';
2
+
3
+ import type { RspackOptions } from '@rspack/core';
4
+
5
+ import { mergeConfig } from './utils/merge-config';
6
+
7
+ export function createFivemRspackConfig(overrides: RspackOptions = {}): RspackOptions {
8
+ const cwd = overrides.context ?? process.cwd();
9
+ const mode =
10
+ overrides.mode ?? (process.env.NODE_ENV === 'production' ? 'production' : 'development');
11
+ const isProduction = mode === 'production';
12
+
13
+ const config: RspackOptions = {
14
+ name: 'fivem',
15
+
16
+ context: cwd,
17
+
18
+ target: 'node16',
19
+ devtool: false,
20
+ mode,
21
+
22
+ entry: path.resolve(cwd, 'src/index.ts'),
23
+
24
+ output: {
25
+ clean: true,
26
+ path: path.resolve(cwd, 'dist'),
27
+ },
28
+
29
+ optimization: {
30
+ minimize: isProduction,
31
+ },
32
+
33
+ resolve: {
34
+ extensions: ['.js', '.json', '.wasm', '.ts'],
35
+ extensionAlias: {
36
+ '.js': ['.ts', '.js'],
37
+ '.cjs': ['.cts', '.cjs'],
38
+ '.mjs': ['.mts', '.mjs'],
39
+ },
40
+ tsConfig: path.resolve(cwd, 'tsconfig.json'),
41
+ },
42
+
43
+ node: {
44
+ global: false,
45
+ __filename: false,
46
+ __dirname: false,
47
+ },
48
+
49
+ externalsPresets: {
50
+ node: true,
51
+ },
52
+
53
+ module: {
54
+ rules: [
55
+ {
56
+ test: /\.(?:ts|cts|mts)$/iu,
57
+ type: 'javascript/auto',
58
+ exclude: [/dist\//u, /node_modules\//u],
59
+ loader: 'builtin:swc-loader',
60
+ options: {
61
+ minify: isProduction,
62
+ module: {
63
+ type: 'nodenext',
64
+ },
65
+ jsc: {
66
+ target: 'es2021',
67
+ parser: {
68
+ syntax: 'typescript',
69
+ },
70
+ transform: {
71
+ useDefineForClassFields: true,
72
+ },
73
+ keepClassNames: true,
74
+ externalHelpers: false,
75
+ },
76
+ },
77
+ },
78
+ ],
79
+ },
80
+
81
+ watchOptions: {
82
+ aggregateTimeout: 200,
83
+ ignored: [
84
+ '**/.git',
85
+ '**/.turbo',
86
+ '**/coverage',
87
+ '**/dist',
88
+ '**/generated',
89
+ '**/old',
90
+ '**/tmp',
91
+ ],
92
+ },
93
+ };
94
+
95
+ return mergeConfig(config, overrides);
96
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './create-fivem-rspack-config';
2
+ export * from './utils/merge-config';
@@ -0,0 +1,13 @@
1
+ import { mergeWithRules } from 'webpack-merge';
2
+
3
+ export const mergeConfig = mergeWithRules({
4
+ module: {
5
+ rules: {
6
+ test: 'match',
7
+ use: {
8
+ loader: 'match',
9
+ options: 'merge',
10
+ },
11
+ },
12
+ },
13
+ });