@jpp-toolkit/rspack-config 0.0.38 → 0.0.39
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.mjs +7 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import rspack, { rspack
|
|
3
|
+
import rspack$1, { rspack } from "@rspack/core";
|
|
4
4
|
import { RunScriptWebpackPlugin } from "run-script-webpack-plugin";
|
|
5
5
|
import nodeExternals from "webpack-node-externals";
|
|
6
6
|
import ReactRefreshPlugin from "@rspack/plugin-react-refresh";
|
|
7
7
|
import fs from "node:fs";
|
|
8
8
|
import { mergeWithRules } from "webpack-merge";
|
|
9
|
-
|
|
10
9
|
//#region src/constants.ts
|
|
11
10
|
const TS_RULE_TEST = /\.(?:ts|tsx|cts|mts)$/iu;
|
|
12
11
|
const ASSET_RULE_TEST = /\.(?:jpe?g|png|gif|svg|webp|avif|ico|bmp|tiff?|eot|ttf|woff2?)$/iu;
|
|
13
12
|
const CSS_RULE_TEST = /\.css$/iu;
|
|
14
13
|
const HASHED_JS_FILENAME_PATTERN = "[name].[contenthash:8].js";
|
|
15
|
-
|
|
16
14
|
//#endregion
|
|
17
15
|
//#region src/presets/base-preset.ts
|
|
18
16
|
const getBasePresetDefaultOptions = (options) => ({
|
|
@@ -88,9 +86,8 @@ const basePreset = (options, context) => ({
|
|
|
88
86
|
aggregateTimeout: 200,
|
|
89
87
|
ignored: options.watchIgnored
|
|
90
88
|
},
|
|
91
|
-
plugins: [new rspack
|
|
89
|
+
plugins: [new rspack.EnvironmentPlugin(options.envVariables)]
|
|
92
90
|
});
|
|
93
|
-
|
|
94
91
|
//#endregion
|
|
95
92
|
//#region src/presets/node-preset.ts
|
|
96
93
|
const getNodePresetDefaultOptions = (options, context) => ({
|
|
@@ -111,12 +108,11 @@ const nodePreset = (options, context) => ({
|
|
|
111
108
|
options: { env: { targets: `node ${options.nodeVersion}` } }
|
|
112
109
|
}] },
|
|
113
110
|
devServer: { devMiddleware: { writeToDisk: true } },
|
|
114
|
-
plugins: [new rspack
|
|
111
|
+
plugins: [new rspack.EnvironmentPlugin(options.envVariables), context.isServeMode && new RunScriptWebpackPlugin({
|
|
115
112
|
name: "main.js",
|
|
116
113
|
autoRestart: false
|
|
117
114
|
})]
|
|
118
115
|
});
|
|
119
|
-
|
|
120
116
|
//#endregion
|
|
121
117
|
//#region src/presets/fivem-script-preset.ts
|
|
122
118
|
const getFivemScriptPresetDefaultOptions = (options, context) => ({
|
|
@@ -128,9 +124,8 @@ const fivemScriptPreset = (options, context) => ({
|
|
|
128
124
|
devtool: false,
|
|
129
125
|
externals: [],
|
|
130
126
|
optimization: { minimize: context.isProduction },
|
|
131
|
-
plugins: [new rspack.EnvironmentPlugin(options.envVariables)]
|
|
127
|
+
plugins: [new rspack$1.EnvironmentPlugin(options.envVariables)]
|
|
132
128
|
});
|
|
133
|
-
|
|
134
129
|
//#endregion
|
|
135
130
|
//#region src/presets/react-preset.ts
|
|
136
131
|
const require = createRequire(import.meta.url);
|
|
@@ -229,11 +224,11 @@ const reactPreset = (options, context) => {
|
|
|
229
224
|
},
|
|
230
225
|
experiments: { css: true },
|
|
231
226
|
plugins: [
|
|
232
|
-
new rspack
|
|
227
|
+
new rspack.EnvironmentPlugin({
|
|
233
228
|
...options.envVariables,
|
|
234
229
|
PUBLIC_URL: publicUrl.toString()
|
|
235
230
|
}),
|
|
236
|
-
new rspack
|
|
231
|
+
new rspack.HtmlRspackPlugin({
|
|
237
232
|
template: path.resolve(context.cwd, options.htmlTemplateFile),
|
|
238
233
|
minify: context.isProduction
|
|
239
234
|
}),
|
|
@@ -241,7 +236,6 @@ const reactPreset = (options, context) => {
|
|
|
241
236
|
]
|
|
242
237
|
};
|
|
243
238
|
};
|
|
244
|
-
|
|
245
239
|
//#endregion
|
|
246
240
|
//#region src/presets/fivem-ui-preset.ts
|
|
247
241
|
const getFivemUiPresetDefaultOptions = (options, context) => {
|
|
@@ -262,14 +256,12 @@ const fivemUiPreset = (_options, context) => ({
|
|
|
262
256
|
devMiddleware: { writeToDisk: true }
|
|
263
257
|
}
|
|
264
258
|
});
|
|
265
|
-
|
|
266
259
|
//#endregion
|
|
267
260
|
//#region src/utils/find-first-existing-file.ts
|
|
268
261
|
function findFirstExistingFile(files, cwd) {
|
|
269
262
|
for (const file of files) if (fs.existsSync(path.resolve(cwd, file))) return file;
|
|
270
263
|
return null;
|
|
271
264
|
}
|
|
272
|
-
|
|
273
265
|
//#endregion
|
|
274
266
|
//#region src/utils/merge-config.ts
|
|
275
267
|
const mergeConfig = mergeWithRules({
|
|
@@ -281,7 +273,6 @@ const mergeConfig = mergeWithRules({
|
|
|
281
273
|
} },
|
|
282
274
|
plugins: "replace"
|
|
283
275
|
});
|
|
284
|
-
|
|
285
276
|
//#endregion
|
|
286
277
|
//#region src/create-rspack-config.ts
|
|
287
278
|
function createConfigBuilder(func) {
|
|
@@ -354,7 +345,7 @@ const createFivemUiRspackConfig = createConfigBuilder((options, context) => {
|
|
|
354
345
|
}, context);
|
|
355
346
|
return mergeConfig(basePreset(presetOptions, context), reactPreset(presetOptions, context), fivemUiPreset(presetOptions, context), { name: "fivem-ui" });
|
|
356
347
|
});
|
|
357
|
-
|
|
358
348
|
//#endregion
|
|
359
349
|
export { createFivemScriptRspackConfig, createFivemUiRspackConfig, createNodeRspackConfig, createReactRspackConfig };
|
|
350
|
+
|
|
360
351
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["rspack","rspack","rspack"],"sources":["../src/constants.ts","../src/presets/base-preset.ts","../src/presets/node-preset.ts","../src/presets/fivem-script-preset.ts","../src/presets/react-preset.ts","../src/presets/fivem-ui-preset.ts","../src/utils/find-first-existing-file.ts","../src/utils/merge-config.ts","../src/create-rspack-config.ts"],"sourcesContent":["export const TS_RULE_TEST = /\\.(?:ts|tsx|cts|mts)$/iu;\nexport const ASSET_RULE_TEST = /\\.(?:jpe?g|png|gif|svg|webp|avif|ico|bmp|tiff?|eot|ttf|woff2?)$/iu;\nexport const CSS_RULE_TEST = /\\.css$/iu;\nexport const HASHED_JS_FILENAME_PATTERN = '[name].[contenthash:8].js';\n","import path from 'node:path';\n\nimport type { SwcLoaderOptions } from '@rspack/core';\nimport { rspack } from '@rspack/core';\n\nimport { TS_RULE_TEST } from '~/constants';\nimport type { GetPresetDefaultOptions, Preset } from '~/types';\n\nexport type BasePresetOptions = {\n readonly entryFile: string;\n readonly tsconfigFile: string;\n readonly outDir: string;\n readonly envVariables: Record<string, string | undefined>;\n readonly useDecorators: boolean;\n readonly watchIgnored: string[];\n};\n\nexport const getBasePresetDefaultOptions: GetPresetDefaultOptions<BasePresetOptions> = (\n options,\n) => ({\n entryFile: options.entryFile ?? 'src/index.js',\n tsconfigFile: options.tsconfigFile ?? 'tsconfig.json',\n outDir: options.outDir ?? 'dist',\n envVariables: options.envVariables ?? {},\n useDecorators: options.useDecorators ?? false,\n watchIgnored: options.watchIgnored ?? [\n '**/.git',\n '**/.turbo',\n '**/coverage',\n '**/dist',\n '**/target',\n '**/generated',\n '**/old',\n '**/tmp',\n ],\n});\n\nexport const basePreset: Preset<BasePresetOptions> = (options, context) => ({\n name: 'base-preset',\n\n context: context.cwd,\n mode: context.isProduction ? 'production' : 'development',\n cache: !context.isProduction,\n\n entry: { main: options.entryFile },\n\n output: {\n clean: true,\n path: path.resolve(context.cwd, options.outDir),\n },\n\n resolve: {\n tsConfig: path.resolve(context.cwd, options.tsconfigFile),\n extensions: ['.ts', '...'],\n extensionAlias: {\n '.js': ['.ts', '.js'],\n '.cts': ['.cts', '.js'],\n '.mjs': ['.mts', '.mjs'],\n },\n },\n\n optimization: { minimize: context.isProduction },\n\n module: {\n rules: [\n {\n test: TS_RULE_TEST,\n type: 'javascript/auto',\n loader: 'builtin:swc-loader',\n exclude: [/dist\\//u, /node_modules\\//u],\n options: {\n jsc: {\n externalHelpers: false,\n keepClassNames: true,\n parser: {\n syntax: 'typescript',\n decorators: options.useDecorators,\n },\n transform: {\n useDefineForClassFields: true,\n legacyDecorator: options.useDecorators,\n decoratorMetadata: options.useDecorators,\n },\n experimental: {\n cacheRoot: path.resolve(context.cwd, 'node_modules/.cache/swc'),\n },\n },\n } satisfies SwcLoaderOptions,\n },\n ],\n },\n\n experiments: {\n cache: {\n type: 'persistent',\n storage: {\n type: 'filesystem',\n directory: path.resolve(context.cwd, 'node_modules/.cache/rspack'),\n },\n },\n },\n\n stats: {\n preset: 'normal',\n errorDetails: true,\n colors: true,\n },\n\n watchOptions: {\n aggregateTimeout: 200,\n ignored: options.watchIgnored,\n },\n\n plugins: [new rspack.EnvironmentPlugin(options.envVariables)],\n});\n","import type { ExternalItem, SwcLoaderOptions } from '@rspack/core';\nimport { rspack } from '@rspack/core';\nimport { RunScriptWebpackPlugin } from 'run-script-webpack-plugin';\nimport nodeExternals from 'webpack-node-externals';\n\nimport { TS_RULE_TEST } from '~/constants';\nimport type { GetPresetDefaultOptions, Preset } from '~/types';\n\nimport type { BasePresetOptions } from './base-preset';\nimport { getBasePresetDefaultOptions } from './base-preset';\n\nexport type NodePresetOptions = BasePresetOptions & {\n readonly nodeVersion: number;\n};\n\nexport const getNodePresetDefaultOptions: GetPresetDefaultOptions<NodePresetOptions> = (\n options,\n context,\n) => ({\n ...getBasePresetDefaultOptions(options, context),\n nodeVersion: options.nodeVersion ?? 24,\n});\n\nexport const nodePreset: Preset<NodePresetOptions> = (options, context) => ({\n name: 'node-preset',\n\n target: `node${options.nodeVersion}`,\n\n entry: {\n main: [...(context.isServeMode ? ['@rspack/core/hot/poll?100'] : []), options.entryFile],\n },\n\n externalsPresets: { node: true },\n externalsType: 'commonjs',\n externals: [\n nodeExternals(\n context.isServeMode ? { allowlist: ['@rspack/core/hot/poll?100'] } : undefined,\n ) as ExternalItem,\n ],\n\n optimization: { minimize: false },\n\n module: {\n rules: [\n {\n test: TS_RULE_TEST,\n loader: 'builtin:swc-loader',\n options: {\n env: { targets: `node ${options.nodeVersion}` },\n } satisfies SwcLoaderOptions,\n },\n ],\n },\n\n devServer: {\n devMiddleware: {\n writeToDisk: true,\n },\n },\n\n plugins: [\n new rspack.EnvironmentPlugin(options.envVariables),\n context.isServeMode && new RunScriptWebpackPlugin({ name: 'main.js', autoRestart: false }),\n ],\n});\n","import rspack from '@rspack/core';\n\nimport type { GetPresetDefaultOptions, Preset } from '~/types';\n\nimport type { NodePresetOptions } from './node-preset';\nimport { getNodePresetDefaultOptions } from './node-preset';\n\nexport type FivemScriptPresetOptions = NodePresetOptions;\n\nexport const getFivemScriptPresetDefaultOptions: GetPresetDefaultOptions<\n FivemScriptPresetOptions\n> = (options, context) => ({\n ...getNodePresetDefaultOptions(options, context),\n nodeVersion: options.nodeVersion ?? 16,\n});\n\nexport const fivemScriptPreset: Preset<FivemScriptPresetOptions> = (options, context) => ({\n name: 'fivem-script-preset',\n\n devtool: false,\n\n externals: [],\n\n optimization: { minimize: context.isProduction },\n\n plugins: [new rspack.EnvironmentPlugin(options.envVariables)],\n});\n","import { createRequire } from 'node:module';\nimport path from 'node:path';\n\nimport type { SwcLoaderOptions } from '@rspack/core';\nimport { rspack } from '@rspack/core';\nimport ReactRefreshPlugin from '@rspack/plugin-react-refresh';\n\nimport {\n ASSET_RULE_TEST,\n CSS_RULE_TEST,\n HASHED_JS_FILENAME_PATTERN,\n TS_RULE_TEST,\n} from '~/constants';\nimport type { GetPresetDefaultOptions, Preset } from '~/types';\n\nimport type { BasePresetOptions } from './base-preset';\nimport { getBasePresetDefaultOptions } from './base-preset';\n\nconst require = createRequire(import.meta.url);\n\nexport type ReactPresetOptions = BasePresetOptions & {\n readonly htmlTemplateFile: string;\n readonly browserlist: string;\n readonly publicUrl: string;\n};\n\nexport const getReactPresetDefaultOptions: GetPresetDefaultOptions<ReactPresetOptions> = (\n options,\n context,\n) => ({\n ...getBasePresetDefaultOptions(options, context),\n htmlTemplateFile: options.htmlTemplateFile ?? 'src/index.html',\n browserlist: options.browserlist ?? 'defaults',\n publicUrl: options.publicUrl ?? 'http://localhost:8080/',\n});\n\nexport const reactPreset: Preset<ReactPresetOptions> = (options, context) => {\n const publicUrl = new URL(options.publicUrl);\n if (!publicUrl.pathname.endsWith('/')) publicUrl.pathname += '/';\n\n return {\n name: 'react-preset',\n\n target: `browserslist:${options.browserlist}`,\n\n output: {\n filename: context.isProduction ? HASHED_JS_FILENAME_PATTERN : '[name].js',\n publicPath: publicUrl.toString(),\n },\n\n resolve: {\n extensions: ['.tsx', '.ts', '.jsx', '...'],\n extensionAlias: {\n '.js': ['.tsx', '.ts', '.jsx', '.js'],\n '.cts': ['.ctsx', '.cts', '.cjsx', '.js'],\n '.mjs': ['.mtsx', '.mts', '.mjsx', '.mjs'],\n },\n },\n\n externalsPresets: { web: true },\n\n module: {\n rules: [\n {\n test: TS_RULE_TEST,\n loader: 'builtin:swc-loader',\n options: {\n env: { targets: options.browserlist },\n jsc: {\n parser: {\n syntax: 'typescript',\n tsx: true,\n },\n transform: {\n react: {\n runtime: 'automatic',\n throwIfNamespace: true,\n useBuiltins: false,\n development: !context.isProduction,\n refresh: context.isServeMode,\n },\n },\n },\n } satisfies SwcLoaderOptions,\n },\n {\n test: ASSET_RULE_TEST,\n type: 'asset/resource',\n },\n {\n test: CSS_RULE_TEST,\n type: 'css',\n use: [\n {\n loader: require.resolve('postcss-loader'),\n options: {\n implementation: require.resolve('postcss'),\n postcssOptions: {\n plugins: [\n [\n require.resolve('@tailwindcss/postcss'),\n { optimize: context.isProduction },\n ],\n ],\n },\n },\n },\n ],\n },\n ],\n },\n\n devServer: {\n host: publicUrl.hostname || undefined,\n port: publicUrl.port || undefined,\n historyApiFallback: true,\n hot: 'only',\n headers: {\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',\n 'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',\n },\n },\n\n experiments: { css: true },\n\n plugins: [\n new rspack.EnvironmentPlugin({\n ...options.envVariables,\n PUBLIC_URL: publicUrl.toString(),\n }),\n new rspack.HtmlRspackPlugin({\n template: path.resolve(context.cwd, options.htmlTemplateFile),\n minify: context.isProduction,\n }),\n context.isServeMode && new ReactRefreshPlugin({ forceEnable: true }),\n ],\n };\n};\n","import path from 'node:path';\n\nimport type { GetPresetDefaultOptions, Preset } from '~/types';\n\nimport type { ReactPresetOptions } from './react-preset';\nimport { getReactPresetDefaultOptions } from './react-preset';\n\nexport type FivemUiPresetOptions = ReactPresetOptions & {\n readonly resourceName: string;\n};\n\nexport const getFivemUiPresetDefaultOptions: GetPresetDefaultOptions<FivemUiPresetOptions> = (\n options,\n context,\n) => {\n const resourceName = options.resourceName ?? path.basename(context.cwd);\n const reactPresetOptions = getReactPresetDefaultOptions(options, context);\n return {\n ...reactPresetOptions,\n resourceName,\n publicUrl:\n options.publicUrl\n ?? (context.isServeMode ? 'http://localhost:8080/' : (\n `https://cfx-nui-${resourceName}/${reactPresetOptions.outDir}/`\n )),\n };\n};\n\nexport const fivemUiPreset: Preset<FivemUiPresetOptions> = (_options, context) => ({\n name: 'fivem-ui-preset',\n\n ...(context.isProduction ? { devtool: false } : {}),\n\n output: { filename: '[name].js' },\n\n devServer: {\n allowedHosts: 'all',\n devMiddleware: {\n writeToDisk: true,\n },\n },\n});\n","import fs from 'node:fs';\nimport path from 'node:path';\n\nexport function findFirstExistingFile(files: string[], cwd: string): string | null {\n for (const file of files) if (fs.existsSync(path.resolve(cwd, file))) return file;\n return null;\n}\n","import type { RspackOptions } from '@rspack/core';\nimport { mergeWithRules } from 'webpack-merge';\n\nexport const mergeConfig = mergeWithRules({\n entry: 'replace',\n externals: 'replace',\n module: {\n rules: {\n test: 'match',\n options: 'merge',\n },\n },\n plugins: 'replace',\n}) as (...configs: RspackOptions[]) => RspackOptions;\n","import type { RspackOptions } from '@rspack/core';\n\nimport type {\n FivemScriptPresetOptions,\n FivemUiPresetOptions,\n NodePresetOptions,\n ReactPresetOptions,\n} from './presets';\nimport {\n basePreset,\n fivemScriptPreset,\n fivemUiPreset,\n getFivemScriptPresetDefaultOptions,\n getFivemUiPresetDefaultOptions,\n getNodePresetDefaultOptions,\n getReactPresetDefaultOptions,\n nodePreset,\n reactPreset,\n} from './presets';\nimport type { RspackEnv, RunContext } from './types';\nimport { findFirstExistingFile } from './utils/find-first-existing-file';\nimport { mergeConfig } from './utils/merge-config';\n\nfunction createConfigBuilder<TOptions, TReturn extends RspackOptions | RspackOptions[]>(\n func: (options: Partial<TOptions>, context: RunContext) => TReturn,\n) {\n return function (options: Partial<TOptions> = {}, context: Partial<RunContext> = {}) {\n return function (env: RspackEnv): TReturn {\n return func(options, {\n cwd: process.cwd(),\n isProduction: process.env.NODE_ENV === 'production',\n isBuildMode: Boolean(env.RSPACK_BUILD),\n isBundleMode: Boolean(env.RSPACK_BUNDLE),\n isWatchMode: Boolean(env.RSPACK_WATCH),\n isServeMode: Boolean(env.RSPACK_SERVE),\n ...context,\n });\n };\n };\n}\n\nexport const createNodeRspackConfig = createConfigBuilder<NodePresetOptions, RspackOptions>(\n (options, context) => {\n const presetOptions = getNodePresetDefaultOptions(options, context);\n\n return mergeConfig(basePreset(presetOptions, context), nodePreset(presetOptions, context), {\n name: 'node',\n });\n },\n);\n\nexport const createReactRspackConfig = createConfigBuilder<ReactPresetOptions, RspackOptions>(\n (options, context) => {\n const presetOptions = getReactPresetDefaultOptions(options, context);\n\n return mergeConfig(\n basePreset(presetOptions, context),\n reactPreset(presetOptions, context),\n {\n name: 'react',\n },\n );\n },\n);\n\nexport const createFivemScriptRspackConfig = createConfigBuilder<\n Omit<FivemScriptPresetOptions, 'entryFile' | 'outDir'>,\n RspackOptions[]\n>((options, context) => {\n const createBuildPreset = (type: 'client' | 'server' | 'shared') => {\n const entryFile = findFirstExistingFile(\n [`src/${type}/index.ts`, `src/${type}.ts`, `src/${type}/index.js`, `src/${type}.js`],\n context.cwd,\n );\n if (!entryFile) return null;\n\n const presetOptions = getFivemScriptPresetDefaultOptions(\n {\n ...options,\n entryFile,\n outDir: `dist/${type}`,\n },\n context,\n );\n\n return mergeConfig(\n basePreset(presetOptions, context),\n nodePreset(presetOptions, context),\n fivemScriptPreset(presetOptions, context),\n { name: `fivem-${type}` },\n );\n };\n\n const configs: (RspackOptions | null)[] = [];\n\n configs.push(createBuildPreset('client'));\n configs.push(createBuildPreset('server'));\n configs.push(createBuildPreset('shared'));\n\n return configs.filter(Boolean) as RspackOptions[];\n});\n\nexport const createFivemUiRspackConfig = createConfigBuilder<\n Omit<FivemUiPresetOptions, 'entryFile' | 'outDir' | 'htmlTemplateFile'>,\n RspackOptions\n>((options, context) => {\n const entryFile = findFirstExistingFile(\n [\n 'src/ui/index.tsx',\n 'src/ui.tsx',\n 'src/ui/index.ts',\n 'src/ui.ts',\n 'src/ui/index.jsx',\n 'src/ui.jsx',\n 'src/ui/index.js',\n 'src/ui.js',\n ],\n context.cwd,\n );\n\n const htmlTemplateFile = findFirstExistingFile(\n ['src/ui/index.html', 'src/ui.html', 'src/index.html'],\n context.cwd,\n );\n\n if (!entryFile || !htmlTemplateFile) return {};\n\n const presetOptions = getFivemUiPresetDefaultOptions(\n {\n ...options,\n entryFile,\n htmlTemplateFile,\n outDir: 'dist/ui',\n },\n context,\n );\n\n return mergeConfig(\n basePreset(presetOptions, context),\n reactPreset(presetOptions, context),\n fivemUiPreset(presetOptions, context),\n { name: 'fivem-ui' },\n );\n});\n"],"mappings":";;;;;;;;;;AAAA,MAAa,eAAe;AAC5B,MAAa,kBAAkB;AAC/B,MAAa,gBAAgB;AAC7B,MAAa,6BAA6B;;;;ACc1C,MAAa,+BACT,aACE;CACF,WAAW,QAAQ,aAAa;CAChC,cAAc,QAAQ,gBAAgB;CACtC,QAAQ,QAAQ,UAAU;CAC1B,cAAc,QAAQ,gBA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,IACX;CAED,MAAM,mBAAmB,sBACrB;EAAC;EAAqB;EAAe;EAAiB,EACtD,QAAQ,IACX;AAED,KAAI,CAAC,aAAa,CAAC,iBAAkB,QAAO,EAAE;CAE9C,MAAM,gBAAgB,+BAClB;EACI,GAAG;EACH;EACA;EACA,QAAQ;EACX,EACD,QACH;AAED,QAAO,YACH,WAAW,eAAe,QAAQ,EAClC,YAAY,eAAe,QAAQ,EACnC,cAAc,eAAe,QAAQ,EACrC,EAAE,MAAM,YAAY,CACvB;EACH"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["rspack"],"sources":["../src/constants.ts","../src/presets/base-preset.ts","../src/presets/node-preset.ts","../src/presets/fivem-script-preset.ts","../src/presets/react-preset.ts","../src/presets/fivem-ui-preset.ts","../src/utils/find-first-existing-file.ts","../src/utils/merge-config.ts","../src/create-rspack-config.ts"],"sourcesContent":["export const TS_RULE_TEST = /\\.(?:ts|tsx|cts|mts)$/iu;\nexport const ASSET_RULE_TEST = /\\.(?:jpe?g|png|gif|svg|webp|avif|ico|bmp|tiff?|eot|ttf|woff2?)$/iu;\nexport const CSS_RULE_TEST = /\\.css$/iu;\nexport const HASHED_JS_FILENAME_PATTERN = '[name].[contenthash:8].js';\n","import path from 'node:path';\n\nimport type { SwcLoaderOptions } from '@rspack/core';\nimport { rspack } from '@rspack/core';\n\nimport { TS_RULE_TEST } from '~/constants';\nimport type { GetPresetDefaultOptions, Preset } from '~/types';\n\nexport type BasePresetOptions = {\n readonly entryFile: string;\n readonly tsconfigFile: string;\n readonly outDir: string;\n readonly envVariables: Record<string, string | undefined>;\n readonly useDecorators: boolean;\n readonly watchIgnored: string[];\n};\n\nexport const getBasePresetDefaultOptions: GetPresetDefaultOptions<BasePresetOptions> = (\n options,\n) => ({\n entryFile: options.entryFile ?? 'src/index.js',\n tsconfigFile: options.tsconfigFile ?? 'tsconfig.json',\n outDir: options.outDir ?? 'dist',\n envVariables: options.envVariables ?? {},\n useDecorators: options.useDecorators ?? false,\n watchIgnored: options.watchIgnored ?? [\n '**/.git',\n '**/.turbo',\n '**/coverage',\n '**/dist',\n '**/target',\n '**/generated',\n '**/old',\n '**/tmp',\n ],\n});\n\nexport const basePreset: Preset<BasePresetOptions> = (options, context) => ({\n name: 'base-preset',\n\n context: context.cwd,\n mode: context.isProduction ? 'production' : 'development',\n cache: !context.isProduction,\n\n entry: { main: options.entryFile },\n\n output: {\n clean: true,\n path: path.resolve(context.cwd, options.outDir),\n },\n\n resolve: {\n tsConfig: path.resolve(context.cwd, options.tsconfigFile),\n extensions: ['.ts', '...'],\n extensionAlias: {\n '.js': ['.ts', '.js'],\n '.cts': ['.cts', '.js'],\n '.mjs': ['.mts', '.mjs'],\n },\n },\n\n optimization: { minimize: context.isProduction },\n\n module: {\n rules: [\n {\n test: TS_RULE_TEST,\n type: 'javascript/auto',\n loader: 'builtin:swc-loader',\n exclude: [/dist\\//u, /node_modules\\//u],\n options: {\n jsc: {\n externalHelpers: false,\n keepClassNames: true,\n parser: {\n syntax: 'typescript',\n decorators: options.useDecorators,\n },\n transform: {\n useDefineForClassFields: true,\n legacyDecorator: options.useDecorators,\n decoratorMetadata: options.useDecorators,\n },\n experimental: {\n cacheRoot: path.resolve(context.cwd, 'node_modules/.cache/swc'),\n },\n },\n } satisfies SwcLoaderOptions,\n },\n ],\n },\n\n experiments: {\n cache: {\n type: 'persistent',\n storage: {\n type: 'filesystem',\n directory: path.resolve(context.cwd, 'node_modules/.cache/rspack'),\n },\n },\n },\n\n stats: {\n preset: 'normal',\n errorDetails: true,\n colors: true,\n },\n\n watchOptions: {\n aggregateTimeout: 200,\n ignored: options.watchIgnored,\n },\n\n plugins: [new rspack.EnvironmentPlugin(options.envVariables)],\n});\n","import type { ExternalItem, SwcLoaderOptions } from '@rspack/core';\nimport { rspack } from '@rspack/core';\nimport { RunScriptWebpackPlugin } from 'run-script-webpack-plugin';\nimport nodeExternals from 'webpack-node-externals';\n\nimport { TS_RULE_TEST } from '~/constants';\nimport type { GetPresetDefaultOptions, Preset } from '~/types';\n\nimport type { BasePresetOptions } from './base-preset';\nimport { getBasePresetDefaultOptions } from './base-preset';\n\nexport type NodePresetOptions = BasePresetOptions & {\n readonly nodeVersion: number;\n};\n\nexport const getNodePresetDefaultOptions: GetPresetDefaultOptions<NodePresetOptions> = (\n options,\n context,\n) => ({\n ...getBasePresetDefaultOptions(options, context),\n nodeVersion: options.nodeVersion ?? 24,\n});\n\nexport const nodePreset: Preset<NodePresetOptions> = (options, context) => ({\n name: 'node-preset',\n\n target: `node${options.nodeVersion}`,\n\n entry: {\n main: [...(context.isServeMode ? ['@rspack/core/hot/poll?100'] : []), options.entryFile],\n },\n\n externalsPresets: { node: true },\n externalsType: 'commonjs',\n externals: [\n nodeExternals(\n context.isServeMode ? { allowlist: ['@rspack/core/hot/poll?100'] } : undefined,\n ) as ExternalItem,\n ],\n\n optimization: { minimize: false },\n\n module: {\n rules: [\n {\n test: TS_RULE_TEST,\n loader: 'builtin:swc-loader',\n options: {\n env: { targets: `node ${options.nodeVersion}` },\n } satisfies SwcLoaderOptions,\n },\n ],\n },\n\n devServer: {\n devMiddleware: {\n writeToDisk: true,\n },\n },\n\n plugins: [\n new rspack.EnvironmentPlugin(options.envVariables),\n context.isServeMode && new RunScriptWebpackPlugin({ name: 'main.js', autoRestart: false }),\n ],\n});\n","import rspack from '@rspack/core';\n\nimport type { GetPresetDefaultOptions, Preset } from '~/types';\n\nimport type { NodePresetOptions } from './node-preset';\nimport { getNodePresetDefaultOptions } from './node-preset';\n\nexport type FivemScriptPresetOptions = NodePresetOptions;\n\nexport const getFivemScriptPresetDefaultOptions: GetPresetDefaultOptions<\n FivemScriptPresetOptions\n> = (options, context) => ({\n ...getNodePresetDefaultOptions(options, context),\n nodeVersion: options.nodeVersion ?? 16,\n});\n\nexport const fivemScriptPreset: Preset<FivemScriptPresetOptions> = (options, context) => ({\n name: 'fivem-script-preset',\n\n devtool: false,\n\n externals: [],\n\n optimization: { minimize: context.isProduction },\n\n plugins: [new rspack.EnvironmentPlugin(options.envVariables)],\n});\n","import { createRequire } from 'node:module';\nimport path from 'node:path';\n\nimport type { SwcLoaderOptions } from '@rspack/core';\nimport { rspack } from '@rspack/core';\nimport ReactRefreshPlugin from '@rspack/plugin-react-refresh';\n\nimport {\n ASSET_RULE_TEST,\n CSS_RULE_TEST,\n HASHED_JS_FILENAME_PATTERN,\n TS_RULE_TEST,\n} from '~/constants';\nimport type { GetPresetDefaultOptions, Preset } from '~/types';\n\nimport type { BasePresetOptions } from './base-preset';\nimport { getBasePresetDefaultOptions } from './base-preset';\n\nconst require = createRequire(import.meta.url);\n\nexport type ReactPresetOptions = BasePresetOptions & {\n readonly htmlTemplateFile: string;\n readonly browserlist: string;\n readonly publicUrl: string;\n};\n\nexport const getReactPresetDefaultOptions: GetPresetDefaultOptions<ReactPresetOptions> = (\n options,\n context,\n) => ({\n ...getBasePresetDefaultOptions(options, context),\n htmlTemplateFile: options.htmlTemplateFile ?? 'src/index.html',\n browserlist: options.browserlist ?? 'defaults',\n publicUrl: options.publicUrl ?? 'http://localhost:8080/',\n});\n\nexport const reactPreset: Preset<ReactPresetOptions> = (options, context) => {\n const publicUrl = new URL(options.publicUrl);\n if (!publicUrl.pathname.endsWith('/')) publicUrl.pathname += '/';\n\n return {\n name: 'react-preset',\n\n target: `browserslist:${options.browserlist}`,\n\n output: {\n filename: context.isProduction ? HASHED_JS_FILENAME_PATTERN : '[name].js',\n publicPath: publicUrl.toString(),\n },\n\n resolve: {\n extensions: ['.tsx', '.ts', '.jsx', '...'],\n extensionAlias: {\n '.js': ['.tsx', '.ts', '.jsx', '.js'],\n '.cts': ['.ctsx', '.cts', '.cjsx', '.js'],\n '.mjs': ['.mtsx', '.mts', '.mjsx', '.mjs'],\n },\n },\n\n externalsPresets: { web: true },\n\n module: {\n rules: [\n {\n test: TS_RULE_TEST,\n loader: 'builtin:swc-loader',\n options: {\n env: { targets: options.browserlist },\n jsc: {\n parser: {\n syntax: 'typescript',\n tsx: true,\n },\n transform: {\n react: {\n runtime: 'automatic',\n throwIfNamespace: true,\n useBuiltins: false,\n development: !context.isProduction,\n refresh: context.isServeMode,\n },\n },\n },\n } satisfies SwcLoaderOptions,\n },\n {\n test: ASSET_RULE_TEST,\n type: 'asset/resource',\n },\n {\n test: CSS_RULE_TEST,\n type: 'css',\n use: [\n {\n loader: require.resolve('postcss-loader'),\n options: {\n implementation: require.resolve('postcss'),\n postcssOptions: {\n plugins: [\n [\n require.resolve('@tailwindcss/postcss'),\n { optimize: context.isProduction },\n ],\n ],\n },\n },\n },\n ],\n },\n ],\n },\n\n devServer: {\n host: publicUrl.hostname || undefined,\n port: publicUrl.port || undefined,\n historyApiFallback: true,\n hot: 'only',\n headers: {\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',\n 'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',\n },\n },\n\n experiments: { css: true },\n\n plugins: [\n new rspack.EnvironmentPlugin({\n ...options.envVariables,\n PUBLIC_URL: publicUrl.toString(),\n }),\n new rspack.HtmlRspackPlugin({\n template: path.resolve(context.cwd, options.htmlTemplateFile),\n minify: context.isProduction,\n }),\n context.isServeMode && new ReactRefreshPlugin({ forceEnable: true }),\n ],\n };\n};\n","import path from 'node:path';\n\nimport type { GetPresetDefaultOptions, Preset } from '~/types';\n\nimport type { ReactPresetOptions } from './react-preset';\nimport { getReactPresetDefaultOptions } from './react-preset';\n\nexport type FivemUiPresetOptions = ReactPresetOptions & {\n readonly resourceName: string;\n};\n\nexport const getFivemUiPresetDefaultOptions: GetPresetDefaultOptions<FivemUiPresetOptions> = (\n options,\n context,\n) => {\n const resourceName = options.resourceName ?? path.basename(context.cwd);\n const reactPresetOptions = getReactPresetDefaultOptions(options, context);\n return {\n ...reactPresetOptions,\n resourceName,\n publicUrl:\n options.publicUrl\n ?? (context.isServeMode ? 'http://localhost:8080/' : (\n `https://cfx-nui-${resourceName}/${reactPresetOptions.outDir}/`\n )),\n };\n};\n\nexport const fivemUiPreset: Preset<FivemUiPresetOptions> = (_options, context) => ({\n name: 'fivem-ui-preset',\n\n ...(context.isProduction ? { devtool: false } : {}),\n\n output: { filename: '[name].js' },\n\n devServer: {\n allowedHosts: 'all',\n devMiddleware: {\n writeToDisk: true,\n },\n },\n});\n","import fs from 'node:fs';\nimport path from 'node:path';\n\nexport function findFirstExistingFile(files: string[], cwd: string): string | null {\n for (const file of files) if (fs.existsSync(path.resolve(cwd, file))) return file;\n return null;\n}\n","import type { RspackOptions } from '@rspack/core';\nimport { mergeWithRules } from 'webpack-merge';\n\nexport const mergeConfig = mergeWithRules({\n entry: 'replace',\n externals: 'replace',\n module: {\n rules: {\n test: 'match',\n options: 'merge',\n },\n },\n plugins: 'replace',\n}) as (...configs: RspackOptions[]) => RspackOptions;\n","import type { RspackOptions } from '@rspack/core';\n\nimport type {\n FivemScriptPresetOptions,\n FivemUiPresetOptions,\n NodePresetOptions,\n ReactPresetOptions,\n} from './presets';\nimport {\n basePreset,\n fivemScriptPreset,\n fivemUiPreset,\n getFivemScriptPresetDefaultOptions,\n getFivemUiPresetDefaultOptions,\n getNodePresetDefaultOptions,\n getReactPresetDefaultOptions,\n nodePreset,\n reactPreset,\n} from './presets';\nimport type { RspackEnv, RunContext } from './types';\nimport { findFirstExistingFile } from './utils/find-first-existing-file';\nimport { mergeConfig } from './utils/merge-config';\n\nfunction createConfigBuilder<TOptions, TReturn extends RspackOptions | RspackOptions[]>(\n func: (options: Partial<TOptions>, context: RunContext) => TReturn,\n) {\n return function (options: Partial<TOptions> = {}, context: Partial<RunContext> = {}) {\n return function (env: RspackEnv): TReturn {\n return func(options, {\n cwd: process.cwd(),\n isProduction: process.env.NODE_ENV === 'production',\n isBuildMode: Boolean(env.RSPACK_BUILD),\n isBundleMode: Boolean(env.RSPACK_BUNDLE),\n isWatchMode: Boolean(env.RSPACK_WATCH),\n isServeMode: Boolean(env.RSPACK_SERVE),\n ...context,\n });\n };\n };\n}\n\nexport const createNodeRspackConfig = createConfigBuilder<NodePresetOptions, RspackOptions>(\n (options, context) => {\n const presetOptions = getNodePresetDefaultOptions(options, context);\n\n return mergeConfig(basePreset(presetOptions, context), nodePreset(presetOptions, context), {\n name: 'node',\n });\n },\n);\n\nexport const createReactRspackConfig = createConfigBuilder<ReactPresetOptions, RspackOptions>(\n (options, context) => {\n const presetOptions = getReactPresetDefaultOptions(options, context);\n\n return mergeConfig(\n basePreset(presetOptions, context),\n reactPreset(presetOptions, context),\n {\n name: 'react',\n },\n );\n },\n);\n\nexport const createFivemScriptRspackConfig = createConfigBuilder<\n Omit<FivemScriptPresetOptions, 'entryFile' | 'outDir'>,\n RspackOptions[]\n>((options, context) => {\n const createBuildPreset = (type: 'client' | 'server' | 'shared') => {\n const entryFile = findFirstExistingFile(\n [`src/${type}/index.ts`, `src/${type}.ts`, `src/${type}/index.js`, `src/${type}.js`],\n context.cwd,\n );\n if (!entryFile) return null;\n\n const presetOptions = getFivemScriptPresetDefaultOptions(\n {\n ...options,\n entryFile,\n outDir: `dist/${type}`,\n },\n context,\n );\n\n return mergeConfig(\n basePreset(presetOptions, context),\n nodePreset(presetOptions, context),\n fivemScriptPreset(presetOptions, context),\n { name: `fivem-${type}` },\n );\n };\n\n const configs: (RspackOptions | null)[] = [];\n\n configs.push(createBuildPreset('client'));\n configs.push(createBuildPreset('server'));\n configs.push(createBuildPreset('shared'));\n\n return configs.filter(Boolean) as RspackOptions[];\n});\n\nexport const createFivemUiRspackConfig = createConfigBuilder<\n Omit<FivemUiPresetOptions, 'entryFile' | 'outDir' | 'htmlTemplateFile'>,\n RspackOptions\n>((options, context) => {\n const entryFile = findFirstExistingFile(\n [\n 'src/ui/index.tsx',\n 'src/ui.tsx',\n 'src/ui/index.ts',\n 'src/ui.ts',\n 'src/ui/index.jsx',\n 'src/ui.jsx',\n 'src/ui/index.js',\n 'src/ui.js',\n ],\n context.cwd,\n );\n\n const htmlTemplateFile = findFirstExistingFile(\n ['src/ui/index.html', 'src/ui.html', 'src/index.html'],\n context.cwd,\n );\n\n if (!entryFile || !htmlTemplateFile) return {};\n\n const presetOptions = getFivemUiPresetDefaultOptions(\n {\n ...options,\n entryFile,\n htmlTemplateFile,\n outDir: 'dist/ui',\n },\n context,\n );\n\n return mergeConfig(\n basePreset(presetOptions, context),\n reactPreset(presetOptions, context),\n fivemUiPreset(presetOptions, context),\n { name: 'fivem-ui' },\n );\n});\n"],"mappings":";;;;;;;;;AAAA,MAAa,eAAe;AAC5B,MAAa,kBAAkB;AAC/B,MAAa,gBAAgB;AAC7B,MAAa,6BAA6B;;;ACc1C,MAAa,+BACT,aACE;CACF,WAAW,QAAQ,aAAa;CAChC,cAAc,QAAQ,gBAAgB;CACtC,QAAQ,QAAQ,UAAU;CAC1B,cAAc,QAAQ,gBAAgB,EAAE;CACxC,eAAe,QAAQ,iBAAiB;CACxC,cAAc,QAAQ,gBAAgB;EAClC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACH;CACJ;AAED,MAAa,cAAyC,SAAS,aAAa;CACxE,MAAM;CAEN,SAAS,QAAQ;CACjB,MAAM,QAAQ,eAAe,eAAe;CAC5C,OAAO,CAAC,QAAQ;CAEhB,OAAO,EAAE,MAAM,QAAQ,WAAW;CAElC,QAAQ;EACJ,OAAO;EACP,MAAM,KAAK,QAAQ,QAAQ,KAAK,QAAQ,OAAO;EAClD;CAED,SAAS;EACL,UAAU,KAAK,QAAQ,QAAQ,KAAK,QAAQ,aAAa;EACzD,YAAY,CAAC,OAAO,MAAM;EAC1B,gBAAgB;GACZ,OAAO,CAAC,OAAO,MAAM;GACrB,QAAQ,CAAC,QAAQ,MAAM;GACvB,QAAQ,CAAC,QAAQ,OAAO;GAC3B;EACJ;CAED,cAAc,EAAE,UAAU,QAAQ,cAAc;CAEhD,QAAQ,EACJ,OAAO,CACH;EACI,MAAM;EACN,MAAM;EACN,QAAQ;EACR,SAAS,CAAC,WAAW,kBAAkB;EACvC,SAAS,EACL,KAAK;GACD,iB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,MAAM,gBAAgB,mCAClB;GACI,GAAG;GACH;GACA,QAAQ,QAAQ;GACnB,EACD,QACH;AAED,SAAO,YACH,WAAW,eAAe,QAAQ,EAClC,WAAW,eAAe,QAAQ,EAClC,kBAAkB,eAAe,QAAQ,EACzC,EAAE,MAAM,SAAS,QAAQ,CAC5B;;CAGL,MAAM,UAAoC,EAAE;AAE5C,SAAQ,KAAK,kBAAkB,SAAS,CAAC;AACzC,SAAQ,KAAK,kBAAkB,SAAS,CAAC;AACzC,SAAQ,KAAK,kBAAkB,SAAS,CAAC;AAEzC,QAAO,QAAQ,OAAO,QAAQ;EAChC;AAEF,MAAa,4BAA4B,qBAGtC,SAAS,YAAY;CACpB,MAAM,YAAY,sBACd;EACI;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACH,EACD,QAAQ,IACX;CAED,MAAM,mBAAmB,sBACrB;EAAC;EAAqB;EAAe;EAAiB,EACtD,QAAQ,IACX;AAED,KAAI,CAAC,aAAa,CAAC,iBAAkB,QAAO,EAAE;CAE9C,MAAM,gBAAgB,+BAClB;EACI,GAAG;EACH;EACA;EACA,QAAQ;EACX,EACD,QACH;AAED,QAAO,YACH,WAAW,eAAe,QAAQ,EAClC,YAAY,eAAe,QAAQ,EACnC,cAAc,eAAe,QAAQ,EACrC,EAAE,MAAM,YAAY,CACvB;EACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jpp-toolkit/rspack-config",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.39",
|
|
4
4
|
"description": "Rspack configurations for JS/TS projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jpp",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"tailwindcss": "4.2.1",
|
|
42
42
|
"webpack-merge": "6.0.1",
|
|
43
43
|
"webpack-node-externals": "3.0.0",
|
|
44
|
-
"@jpp-toolkit/logger": "0.0.
|
|
45
|
-
"@jpp-toolkit/utils": "0.0.
|
|
44
|
+
"@jpp-toolkit/logger": "0.0.30",
|
|
45
|
+
"@jpp-toolkit/utils": "0.0.30"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/webpack-node-externals": "3.0.4"
|