@jpp-toolkit/rspack-config 0.0.60 → 0.0.62

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 CHANGED
@@ -3,7 +3,7 @@ import path from "node:path";
3
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
- import ReactRefreshPlugin from "@rspack/plugin-react-refresh";
6
+ import { ReactRefreshRspackPlugin } from "@rspack/plugin-react-refresh";
7
7
  import fs from "node:fs";
8
8
  import { mergeWithRules } from "webpack-merge";
9
9
  //#region src/constants.ts
@@ -34,7 +34,6 @@ const basePreset = (options, context) => ({
34
34
  name: "base-preset",
35
35
  context: context.cwd,
36
36
  mode: context.isProduction ? "production" : "development",
37
- cache: !context.isProduction,
38
37
  entry: { main: options.entryFile },
39
38
  output: {
40
39
  clean: true,
@@ -70,13 +69,13 @@ const basePreset = (options, context) => ({
70
69
  experimental: { cacheRoot: path.resolve(context.cwd, "node_modules/.cache/swc") }
71
70
  } }
72
71
  }] },
73
- experiments: { cache: {
72
+ cache: !context.isProduction ? {
74
73
  type: "persistent",
75
74
  storage: {
76
75
  type: "filesystem",
77
76
  directory: path.resolve(context.cwd, "node_modules/.cache/rspack")
78
77
  }
79
- } },
78
+ } : false,
80
79
  stats: {
81
80
  preset: "normal",
82
81
  errorDetails: true,
@@ -212,8 +211,8 @@ const reactPreset = (options, context) => {
212
211
  }
213
212
  ] },
214
213
  devServer: {
215
- host: publicUrl.hostname || void 0,
216
- port: publicUrl.port || void 0,
214
+ ...publicUrl.hostname ? { host: publicUrl.hostname } : {},
215
+ ...publicUrl.port ? { port: publicUrl.port } : {},
217
216
  historyApiFallback: true,
218
217
  hot: "only",
219
218
  headers: {
@@ -232,7 +231,7 @@ const reactPreset = (options, context) => {
232
231
  template: path.resolve(context.cwd, options.htmlTemplateFile),
233
232
  minify: context.isProduction
234
233
  }),
235
- context.isServeMode && new ReactRefreshPlugin({ forceEnable: true })
234
+ context.isServeMode && new ReactRefreshRspackPlugin({ forceEnable: true })
236
235
  ]
237
236
  };
238
237
  };
@@ -1 +1 @@
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),\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;;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"}
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\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 cache:\n !context.isProduction ?\n {\n type: 'persistent',\n storage: {\n type: 'filesystem',\n directory: path.resolve(context.cwd, 'node_modules/.cache/rspack'),\n },\n }\n : false,\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 { ReactRefreshRspackPlugin } 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 ...(publicUrl.hostname ? { host: publicUrl.hostname } : {}),\n ...(publicUrl.port ? { port: publicUrl.port } : {}),\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 ReactRefreshRspackPlugin({ 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,CAAC;CACvC,eAAe,QAAQ,iBAAiB;CACxC,cAAc,QAAQ,gBAAgB;EAClC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACJ;AACJ;AAEA,MAAa,cAAyC,SAAS,aAAa;CACxE,MAAM;CAEN,SAAS,QAAQ;CACjB,MAAM,QAAQ,eAAe,eAAe;CAE5C,OAAO,EAAE,MAAM,QAAQ,UAAU;CAEjC,QAAQ;EACJ,OAAO;EACP,MAAM,KAAK,QAAQ,QAAQ,KAAK,QAAQ,MAAM;CAClD;CAEA,SAAS;EACL,UAAU,KAAK,QAAQ,QAAQ,KAAK,QAAQ,YAAY;EAC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AAO,GACpC,EAAE,MAAM,WAAW,CACvB;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jpp-toolkit/rspack-config",
3
- "version": "0.0.60",
3
+ "version": "0.0.62",
4
4
  "description": "Rspack configurations for JS/TS projects.",
5
5
  "keywords": [
6
6
  "jpp",
@@ -31,25 +31,25 @@
31
31
  "src"
32
32
  ],
33
33
  "dependencies": {
34
- "@rspack/core": "1.7.11",
35
- "@rspack/plugin-react-refresh": "1.6.2",
36
- "@tailwindcss/postcss": "4.2.4",
34
+ "@rspack/core": "2.0.3",
35
+ "@rspack/plugin-react-refresh": "2.0.0",
36
+ "@tailwindcss/postcss": "4.3.0",
37
37
  "postcss": "8.5.14",
38
38
  "postcss-loader": "8.2.1",
39
39
  "react-refresh": "0.18.0",
40
40
  "run-script-webpack-plugin": "0.2.3",
41
- "tailwindcss": "4.2.4",
41
+ "tailwindcss": "4.3.0",
42
42
  "webpack-merge": "6.0.1",
43
43
  "webpack-node-externals": "3.0.0",
44
- "@jpp-toolkit/logger": "0.0.37",
45
- "@jpp-toolkit/utils": "0.0.37"
44
+ "@jpp-toolkit/logger": "0.0.38",
45
+ "@jpp-toolkit/utils": "0.0.38"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/webpack-node-externals": "3.0.4"
49
49
  },
50
50
  "engines": {
51
51
  "node": "24",
52
- "pnpm": "10"
52
+ "pnpm": "11"
53
53
  },
54
54
  "volta": {
55
55
  "extends": "../../package.json"
@@ -40,7 +40,6 @@ export const basePreset: Preset<BasePresetOptions> = (options, context) => ({
40
40
 
41
41
  context: context.cwd,
42
42
  mode: context.isProduction ? 'production' : 'development',
43
- cache: !context.isProduction,
44
43
 
45
44
  entry: { main: options.entryFile },
46
45
 
@@ -90,15 +89,16 @@ export const basePreset: Preset<BasePresetOptions> = (options, context) => ({
90
89
  ],
91
90
  },
92
91
 
93
- experiments: {
94
- cache: {
95
- type: 'persistent',
96
- storage: {
97
- type: 'filesystem',
98
- directory: path.resolve(context.cwd, 'node_modules/.cache/rspack'),
99
- },
100
- },
101
- },
92
+ cache:
93
+ !context.isProduction ?
94
+ {
95
+ type: 'persistent',
96
+ storage: {
97
+ type: 'filesystem',
98
+ directory: path.resolve(context.cwd, 'node_modules/.cache/rspack'),
99
+ },
100
+ }
101
+ : false,
102
102
 
103
103
  stats: {
104
104
  preset: 'normal',
@@ -3,7 +3,7 @@ import path from 'node:path';
3
3
 
4
4
  import type { SwcLoaderOptions } from '@rspack/core';
5
5
  import { rspack } from '@rspack/core';
6
- import ReactRefreshPlugin from '@rspack/plugin-react-refresh';
6
+ import { ReactRefreshRspackPlugin } from '@rspack/plugin-react-refresh';
7
7
 
8
8
  import {
9
9
  ASSET_RULE_TEST,
@@ -111,8 +111,8 @@ export const reactPreset: Preset<ReactPresetOptions> = (options, context) => {
111
111
  },
112
112
 
113
113
  devServer: {
114
- host: publicUrl.hostname || undefined,
115
- port: publicUrl.port || undefined,
114
+ ...(publicUrl.hostname ? { host: publicUrl.hostname } : {}),
115
+ ...(publicUrl.port ? { port: publicUrl.port } : {}),
116
116
  historyApiFallback: true,
117
117
  hot: 'only',
118
118
  headers: {
@@ -133,7 +133,7 @@ export const reactPreset: Preset<ReactPresetOptions> = (options, context) => {
133
133
  template: path.resolve(context.cwd, options.htmlTemplateFile),
134
134
  minify: context.isProduction,
135
135
  }),
136
- context.isServeMode && new ReactRefreshPlugin({ forceEnable: true }),
136
+ context.isServeMode && new ReactRefreshRspackPlugin({ forceEnable: true }),
137
137
  ],
138
138
  };
139
139
  };