diff --git a/packages/core/package.json b/packages/core/package.json index 3f42338c1..19a9a5432 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -55,6 +55,7 @@ "chokidar": "^4.0.3", "fs-extra": "^11.3.1", "memfs": "^4.38.1", + "path-serializer": "0.5.1", "picocolors": "1.1.1", "prebundle": "1.4.1", "rsbuild-plugin-publint": "^0.3.3", diff --git a/packages/core/rstest.config.ts b/packages/core/rstest.config.ts index c72db6bfd..cd7e33c6a 100644 --- a/packages/core/rstest.config.ts +++ b/packages/core/rstest.config.ts @@ -4,4 +4,5 @@ import { shared } from '../../rstest.workspace'; export default defineConfig({ ...shared, name: 'unit', + setupFiles: ['./setupRstestTests.ts'], }); diff --git a/packages/core/setupRstestTests.ts b/packages/core/setupRstestTests.ts new file mode 100644 index 000000000..a65b89791 --- /dev/null +++ b/packages/core/setupRstestTests.ts @@ -0,0 +1,40 @@ +import path from 'node:path'; +import process from 'node:process'; +import { beforeEach, expect } from '@rstest/core'; +import { createSnapshotSerializer } from 'path-serializer'; + +beforeEach(() => { + // since our NODE_ENV injection logic is via cli, we need to + // delete "test" NODE_ENV to avoid affecting the default build config + delete process.env.NODE_ENV; +}); + +function removeTrailingSlash(inputPath: string): string { + return path.normalize(inputPath).replace(/[\\/]+$/, ''); +} +expect.addSnapshotSerializer( + createSnapshotSerializer({ + root: removeTrailingSlash(path.join(__dirname, '../../')), + workspace: __dirname, + features: { + replaceHomeDir: false, + replaceWorkspace: true, + replaceRoot: true, + escapeDoubleQuotes: false, + transformCLR: false, + }, + }), +); + +if (process.env.ECO_CI) { + expect.extend({ + toMatchSnapshot: () => ({ + pass: true, + message: () => 'Snapshot always passes', + }), + toMatchInlineSnapshot: () => ({ + pass: true, + message: () => 'Snapshot always passes', + }), + }); +} diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index 45f4db927..f03b2b253 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -818,6 +818,16 @@ const disableUrlParseRsbuildPlugin = (): RsbuildPlugin => ({ }, }); +// Port https://github.com/web-infra-dev/rsbuild/pull/5955 before it merged into Rsbuild. +const fixJsModuleTypePlugin = (): RsbuildPlugin => ({ + name: 'rsbuild:fix-js-module-type', + setup(api) { + api.modifyBundlerChain((config, { CHAIN_ID }) => { + config.module.rule(CHAIN_ID.RULE.JS).delete('type'); + }); + }, +}); + const composeShimsConfig = ( format: Format, shims?: Shims, @@ -866,6 +876,7 @@ const composeShimsConfig = ( plugins: [ resolvedShims.esm.require && pluginEsmRequireShim(), disableUrlParseRsbuildPlugin(), + fixJsModuleTypePlugin(), ].filter(Boolean), }; break; @@ -875,12 +886,16 @@ const composeShimsConfig = ( plugins: [ resolvedShims.cjs['import.meta.url'] && pluginCjsImportMetaUrlShim(), disableUrlParseRsbuildPlugin(), + fixJsModuleTypePlugin(), ].filter(Boolean), }; break; case 'umd': case 'iife': case 'mf': + rsbuildConfig = { + plugins: [fixJsModuleTypePlugin()], + }; break; default: throw new Error(`Unsupported format: ${format}`); diff --git a/packages/core/tests/__snapshots__/config.test.ts.snap b/packages/core/tests/__snapshots__/config.test.ts.snap index 8b2a58b5f..87585b114 100644 --- a/packages/core/tests/__snapshots__/config.test.ts.snap +++ b/packages/core/tests/__snapshots__/config.test.ts.snap @@ -1,5 +1,3443 @@ // Rstest Snapshot v1 +exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config in each format > inspected Rsbuild configs 1`] = ` +"{ + dev: { + hmr: true, + liveReload: true, + watchFiles: [ + { + paths: [ + '/tsconfig.json' + ], + type: 'reload-server' + } + ], + assetPrefix: '/', + writeToDisk: false, + cliShortcuts: false, + client: { + path: '/rsbuild-hmr', + port: '', + host: '', + overlay: true, + reconnect: 100 + }, + lazyCompilation: { + imports: true, + entries: false + } + }, + server: { + port: 3000, + host: '0.0.0.0', + open: false, + base: '/', + htmlFallback: 'index', + compress: true, + printUrls: true, + strictPort: false, + cors: { + origin: /^https?:\\/\\/(?:(?:[^:]+\\.)?localhost|127\\.0\\.0\\.1|\\[::1\\])(?::\\d+)?$/ + }, + middlewareMode: false + }, + html: { + meta: { + charset: { + charset: 'UTF-8' + }, + viewport: 'width=device-width, initial-scale=1.0' + }, + title: 'Rsbuild App', + inject: 'head', + mountId: 'root', + crossorigin: false, + outputStructure: 'flat', + scriptLoading: 'defer' + }, + resolve: { + alias: { + '@swc/helpers': '/node_modules//@swc/helpers' + }, + aliasStrategy: 'prefer-tsconfig', + extensions: [ + '.ts', + '.tsx', + '.mjs', + '.js', + '.jsx', + '.json' + ] + }, + source: { + define: {}, + preEntry: [], + decorators: { + version: '2022-03' + }, + tsconfigPath: '/tsconfig.json' + }, + output: { + target: 'web', + cleanDistPath: 'auto', + distPath: { + root: 'dist', + css: 'static/css', + svg: 'static/svg', + font: 'static/font', + html: './', + wasm: 'static/wasm', + image: 'static/image', + media: 'static/media', + assets: 'static/assets', + favicon: './' + }, + assetPrefix: '/', + filename: {}, + charset: 'utf8', + polyfill: 'off', + dataUriLimit: { + svg: 4096, + font: 4096, + image: 4096, + media: 4096, + assets: 4096 + }, + legalComments: 'linked', + injectStyles: false, + minify: true, + module: false, + manifest: false, + sourceMap: { + js: undefined, + css: false + }, + filenameHash: true, + inlineScripts: false, + inlineStyles: false, + cssModules: { + auto: true, + namedExport: false, + exportGlobals: false, + exportLocalsConvention: 'camelCase' + }, + emitAssets: true + }, + tools: { + cssExtract: { + loaderOptions: {}, + pluginOptions: { + ignoreOrder: true + } + } + }, + security: { + nonce: '', + sri: { + enable: false + } + }, + performance: { + profile: false, + printFileSize: true, + removeConsole: false, + removeMomentLocale: false, + chunkSplit: { + strategy: 'split-by-experience' + } + }, + mode: 'production', + root: '', + plugins: [ + { + name: 'rsbuild:basic', + setup() {} + }, + { + name: 'rsbuild:entry', + setup() {} + }, + { + name: 'rsbuild:cache', + setup() {} + }, + { + name: 'rsbuild:target', + setup() {} + }, + { + name: 'rsbuild:output', + setup() {} + }, + { + name: 'rsbuild:resolve', + setup() {} + }, + { + name: 'rsbuild:file-size', + setup() {} + }, + { + name: 'rsbuild:clean-output', + setup() {} + }, + { + name: 'rsbuild:asset', + setup() {} + }, + { + name: 'rsbuild:html', + setup() {} + }, + { + name: 'rsbuild:app-icon', + setup() {} + }, + { + name: 'rsbuild:wasm', + setup() {} + }, + { + name: 'rsbuild:moment', + setup() {} + }, + { + name: 'rsbuild:node-addons', + setup() {} + }, + { + name: 'rsbuild:define', + setup() {} + }, + { + name: 'rsbuild:css', + setup() {} + }, + { + name: 'rsbuild:minimize', + setup() {} + }, + { + name: 'rsbuild:progress', + setup() {} + }, + { + name: 'rsbuild:swc', + setup() {} + }, + { + name: 'rsbuild:esm', + setup() {} + }, + { + name: 'rsbuild:externals', + setup() {} + }, + { + name: 'rsbuild:split-chunks', + setup() {} + }, + { + name: 'rsbuild:inline-chunk', + setup() {} + }, + { + name: 'rsbuild:rsdoctor', + setup() {} + }, + { + name: 'rsbuild:resource-hints', + setup() {} + }, + { + name: 'rsbuild:performance', + setup() {} + }, + { + name: 'rsbuild:bundle-analyzer', + setup() {} + }, + { + name: 'rsbuild:server', + setup() {} + }, + { + name: 'rsbuild:manifest', + setup() {} + }, + { + name: 'rsbuild:module-federation', + setup() {} + }, + { + name: 'rsbuild:rspack-profile', + setup() {} + }, + { + name: 'rsbuild:lazy-compilation', + apply: 'serve', + setup() {} + }, + { + name: 'rsbuild:sri', + setup() {} + }, + { + name: 'rsbuild:nonce', + setup() {} + } + ] +}" +`; + +exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config in each format > inspected Rspack configs 1`] = ` +[ + "{ + target: [ + 'es2022', + 'node' + ], + name: 'esm', + devtool: false, + context: '', + mode: 'production', + infrastructureLogging: { + level: 'error' + }, + watchOptions: { + aggregateTimeout: 0 + }, + experiments: { + lazyBarrel: true, + inlineEnum: true, + typeReexportsPresence: true, + rspackFuture: { + bundlerInfo: { + force: false + } + }, + asyncWebAssembly: true, + outputModule: true + }, + externals: [ + function () { /* omitted long function */ }, + /^@rsbuild\\/core($|\\/|\\\\)/, + /^rsbuild-plugin-dts($|\\/|\\\\)/, + /^tinyglobby($|\\/|\\\\)/, + /^@microsoft\\/api-extractor($|\\/|\\\\)/, + /^typescript($|\\/|\\\\)/, + '@rsbuild/core', + 'rsbuild-plugin-dts', + 'tinyglobby', + '@microsoft/api-extractor', + 'typescript', + 'assert', + 'assert/strict', + 'async_hooks', + 'buffer', + 'child_process', + 'cluster', + 'console', + 'constants', + 'crypto', + 'dgram', + 'diagnostics_channel', + 'dns', + 'dns/promises', + 'domain', + 'events', + 'fs', + 'fs/promises', + 'http', + 'http2', + 'https', + 'inspector', + 'inspector/promises', + 'module', + 'net', + 'os', + 'path', + 'path/posix', + 'path/win32', + 'perf_hooks', + 'process', + 'punycode', + 'querystring', + 'readline', + 'readline/promises', + 'repl', + 'stream', + 'stream/consumers', + 'stream/promises', + 'stream/web', + 'string_decoder', + 'sys', + 'timers', + 'timers/promises', + 'tls', + 'trace_events', + 'tty', + 'url', + 'util', + 'util/types', + 'v8', + 'vm', + 'wasi', + 'worker_threads', + 'zlib', + /^node:/, + 'pnpapi' + ], + output: { + path: '/dist', + filename: '[name].js', + chunkFilename: '[name].js', + publicPath: 'auto', + pathinfo: false, + hashFunction: 'xxhash64', + library: { + type: 'modern-module' + }, + assetModuleFilename: 'static/assets/[name][ext]', + webassemblyModuleFilename: 'static/wasm/[contenthash:8].module.wasm', + module: true, + chunkFormat: 'module', + chunkLoading: 'import', + workerChunkLoading: 'import' + }, + resolve: { + tsConfig: { + configFile: '/tsconfig.json', + references: 'auto' + }, + alias: { + '@swc/helpers': '/node_modules//@swc/helpers', + foo: 'foo/esm', + bar: 'bar' + }, + extensionAlias: { + '.js': [ + '.js', + '.ts', + '.tsx', + '.ts', + '.tsx', + '.js', + '.jsx', + '.ts', + '.tsx' + ], + '.jsx': [ + '.jsx', + '.tsx', + '.tsx', + '.jsx' + ], + '.mjs': [ + '.mts', + '.mjs' + ], + '.cjs': [ + '.cts', + '.cjs' + ] + }, + extensions: [ + '.ts', + '.tsx', + '.mjs', + '.js', + '.jsx', + '.json' + ] + }, + module: { + parser: { + javascript: { + exportsPresence: 'error', + typeReexportsPresence: 'tolerant', + importMeta: false, + importDynamic: false, + requireResolve: false, + requireDynamic: false, + requireAsExpression: false, + worker: false + } + }, + rules: [ + /* config.module.rule('mjs') */ + { + test: /\\.m?js/, + resolve: { + fullySpecified: false + } + }, + /* config.module.rule('css') */ + { + test: /\\.css$/, + type: 'javascript/auto', + dependency: { + not: 'url' + }, + resourceQuery: { + not: [ + /[?&]raw(?:&|=|$)/, + /[?&]inline(?:&|=|$)/ + ] + }, + sideEffects: true, + use: [ + /* config.module.rule('css').use('ignore-css') */ + { + loader: '/node_modules//@rsbuild/core/dist/ignoreCssLoader.mjs' + }, + /* config.module.rule('css').use('css') */ + { + loader: '/node_modules//@rsbuild/core/compiled/css-loader/index.js', + options: { + importLoaders: 0, + modules: { + auto: true, + namedExport: false, + exportGlobals: false, + exportLocalsConvention: 'camelCase', + localIdentName: '[local]-[hash:base64:6]', + exportOnlyLocals: true + }, + sourceMap: false + } + } + ], + resolve: { + preferRelative: true + } + }, + /* config.module.rule('css-inline') */ + { + test: /\\.css$/, + type: 'javascript/auto', + resourceQuery: /[?&]inline(?:&|=|$)/, + sideEffects: true, + use: [ + /* config.module.rule('css-inline').use('css') */ + { + loader: '/node_modules//@rsbuild/core/compiled/css-loader/index.js', + options: { + importLoaders: 0, + modules: false, + sourceMap: false, + exportType: 'string' + } + } + ], + resolve: { + preferRelative: true + } + }, + /* config.module.rule('css-raw') */ + { + test: /\\.css$/, + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('js') */ + { + test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, + dependency: { + not: 'url' + }, + resourceQuery: { + not: /[?&]raw(?:&|=|$)/ + }, + parser: { + url: false + }, + include: [ + { + not: /[\\\\/]node_modules[\\\\/]/ + }, + /\\.(?:ts|tsx|jsx|mts|cts)$/ + ], + use: [ + /* config.module.rule('js').use('swc') */ + { + loader: 'builtin:swc-loader', + options: { + jsc: { + externalHelpers: false, + parser: { + tsx: false, + syntax: 'typescript', + decorators: true + }, + experimental: { + cacheRoot: '/node_modules/.cache/.swc', + keepImportAttributes: true + }, + output: { + charset: 'utf8' + }, + transform: { + legacyDecorator: false, + decoratorVersion: '2022-03' + } + }, + isModule: 'unknown', + env: { + targets: [ + 'last 1 node versions' + ] + }, + rspackExperiments: { + collectTypeScriptInfo: { + typeExports: true, + exportedEnum: true + } + } + } + } + ] + }, + /* config.module.rule('js-raw') */ + { + test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('js-data-uri') */ + { + mimetype: { + or: [ + 'text/javascript', + 'application/javascript' + ] + }, + use: [ + /* config.module.rule('js-data-uri').use('swc') */ + { + loader: 'builtin:swc-loader', + options: { + jsc: { + externalHelpers: false, + parser: { + tsx: false, + syntax: 'typescript', + decorators: true + }, + experimental: { + cacheRoot: '/node_modules/.cache/.swc', + keepImportAttributes: true + }, + output: { + charset: 'utf8' + }, + transform: { + legacyDecorator: false, + decoratorVersion: '2022-03' + } + }, + isModule: 'unknown', + env: { + targets: [ + 'last 1 node versions' + ] + }, + rspackExperiments: { + collectTypeScriptInfo: { + typeExports: true, + exportedEnum: true + } + } + } + } + ], + resolve: { + fullySpecified: false + } + }, + /* config.module.rule('image') */ + { + test: /\\.(?:png|jpg|jpeg|pjpeg|pjp|gif|bmp|webp|ico|apng|avif|tif|tiff|jfif|cur)$/i, + oneOf: [ + /* config.module.rule('image').oneOf('image-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/image/[name][ext]' + } + }, + /* config.module.rule('image').oneOf('image-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('image').oneOf('image-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('image').oneOf('image-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 0 + } + }, + generator: { + filename: 'static/image/[name][ext]', + importMode: 'preserve' + }, + issuer: { + not: /\\.(css|sass|scss|less|styl|stylus)$/ + } + }, + /* config.module.rule('image').oneOf('image-asset-for-css') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 0 + } + }, + generator: { + filename: 'static/image/[name][ext]' + }, + issuer: /\\.(css|sass|scss|less|styl|stylus)$/ + } + ] + }, + /* config.module.rule('svg') */ + { + test: /\\.svg$/i, + oneOf: [ + /* config.module.rule('svg').oneOf('svg-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/svg/[name].svg' + } + }, + /* config.module.rule('svg').oneOf('svg-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('svg').oneOf('svg-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('svg').oneOf('svg-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 0 + } + }, + generator: { + filename: 'static/svg/[name].svg', + importMode: 'preserve' + }, + issuer: { + not: /\\.(css|sass|scss|less|styl|stylus)$/ + } + }, + /* config.module.rule('svg').oneOf('svg-asset-for-css') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 0 + } + }, + generator: { + filename: 'static/svg/[name].svg' + }, + issuer: /\\.(css|sass|scss|less|styl|stylus)$/ + }, + /* config.module.rule('svg').oneOf('svg') */ + {} + ] + }, + /* config.module.rule('media') */ + { + test: /\\.(?:mp4|webm|ogg|mov|mp3|wav|flac|aac|m4a|opus)$/i, + oneOf: [ + /* config.module.rule('media').oneOf('media-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/media/[name][ext]' + } + }, + /* config.module.rule('media').oneOf('media-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('media').oneOf('media-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('media').oneOf('media-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 0 + } + }, + generator: { + filename: 'static/media/[name][ext]', + importMode: 'preserve' + }, + issuer: { + not: /\\.(css|sass|scss|less|styl|stylus)$/ + } + }, + /* config.module.rule('media').oneOf('media-asset-for-css') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 0 + } + }, + generator: { + filename: 'static/media/[name][ext]' + }, + issuer: /\\.(css|sass|scss|less|styl|stylus)$/ + } + ] + }, + /* config.module.rule('font') */ + { + test: /\\.(?:woff|woff2|eot|ttf|otf|ttc)$/i, + oneOf: [ + /* config.module.rule('font').oneOf('font-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/font/[name][ext]' + } + }, + /* config.module.rule('font').oneOf('font-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('font').oneOf('font-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('font').oneOf('font-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 0 + } + }, + generator: { + filename: 'static/font/[name][ext]', + importMode: 'preserve' + }, + issuer: { + not: /\\.(css|sass|scss|less|styl|stylus)$/ + } + }, + /* config.module.rule('font').oneOf('font-asset-for-css') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 0 + } + }, + generator: { + filename: 'static/font/[name][ext]' + }, + issuer: /\\.(css|sass|scss|less|styl|stylus)$/ + } + ] + }, + /* config.module.rule('wasm') */ + { + test: /\\.wasm$/, + dependency: 'url', + type: 'asset/resource', + generator: { + filename: 'static/wasm/[contenthash:8].module.wasm' + } + }, + /* config.module.rule('rsbuild-transform-0') */ + { + test: /\\.node$/, + use: [ + /* config.module.rule('rsbuild-transform-0').use('rsbuild-transform-0') */ + { + loader: '/node_modules//@rsbuild/core/dist/transformRawLoader.mjs', + options: { + id: 'rsbuild-transform-0', + getEnvironment: ()=>environment + } + } + ] + }, + /* config.module.rule('Rslib:js-entry-loader') */ + { + test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, + issuer: /^$/, + use: [ + /* config.module.rule('Rslib:js-entry-loader').use('rsbuild:lib-entry-module') */ + { + loader: '/dist/entryModuleLoader.js' + } + ] + } + ] + }, + optimization: { + minimize: true, + splitChunks: { + chunks: 'async' + }, + minimizer: [ + /* config.optimization.minimizer('js') */ + new SwcJsMinimizerRspackPlugin( + { + minimizerOptions: { + format: { + asciiOnly: false, + comments: 'some', + preserve_annotations: true + }, + mangle: false, + minify: false, + compress: { + defaults: false, + unused: true, + dead_code: true, + toplevel: true + } + }, + extractComments: true + } + ) + ], + moduleIds: 'named', + nodeEnv: false, + concatenateModules: true, + sideEffects: 'flag', + avoidEntryIife: true + }, + plugins: [ + /* config.plugin('RsbuildCorePlugin') */ + {}, + /* config.plugin('define') */ + new DefinePlugin( + { + 'import.meta.env.MODE': '"production"', + 'import.meta.env.DEV': false, + 'import.meta.env.PROD': true, + 'import.meta.env.BASE_URL': '"/"', + 'import.meta.env.ASSET_PREFIX': '"auto"', + 'process.env.BASE_URL': '"/"', + 'process.env.ASSET_PREFIX': '"auto"' + } + ), + { + affectedHooks: undefined, + name: 'RslibPlugin', + _args: [ + { + interceptApiPlugin: true + } + ] + }, + { + reactDirectives: {}, + shimsInjectedAssets: new Set([]), + shebangChmod: 493, + shebangEntries: {}, + shebangInjectedAssets: new Set([]), + enabledImportMetaUrlShim: false, + contextToWatch: null + } + ], + performance: { + hints: false + }, + entry: { + index: [ + './b.js', + '/src/index.ts' + ] + }, + node: { + __dirname: false, + __filename: false + }, + externalsType: 'module-import' +}", + "{ + target: [ + 'es2022', + 'node' + ], + name: 'cjs', + devtool: false, + context: '', + mode: 'production', + infrastructureLogging: { + level: 'error' + }, + watchOptions: { + aggregateTimeout: 0 + }, + experiments: { + lazyBarrel: true, + inlineEnum: true, + typeReexportsPresence: true, + rspackFuture: { + bundlerInfo: { + force: false + } + }, + asyncWebAssembly: true + }, + externals: [ + /^@rsbuild\\/core($|\\/|\\\\)/, + /^rsbuild-plugin-dts($|\\/|\\\\)/, + /^tinyglobby($|\\/|\\\\)/, + /^@microsoft\\/api-extractor($|\\/|\\\\)/, + /^typescript($|\\/|\\\\)/, + '@rsbuild/core', + 'rsbuild-plugin-dts', + 'tinyglobby', + '@microsoft/api-extractor', + 'typescript', + 'assert', + 'assert/strict', + 'async_hooks', + 'buffer', + 'child_process', + 'cluster', + 'console', + 'constants', + 'crypto', + 'dgram', + 'diagnostics_channel', + 'dns', + 'dns/promises', + 'domain', + 'events', + 'fs', + 'fs/promises', + 'http', + 'http2', + 'https', + 'inspector', + 'inspector/promises', + 'module', + 'net', + 'os', + 'path', + 'path/posix', + 'path/win32', + 'perf_hooks', + 'process', + 'punycode', + 'querystring', + 'readline', + 'readline/promises', + 'repl', + 'stream', + 'stream/consumers', + 'stream/promises', + 'stream/web', + 'string_decoder', + 'sys', + 'timers', + 'timers/promises', + 'tls', + 'trace_events', + 'tty', + 'url', + 'util', + 'util/types', + 'v8', + 'vm', + 'wasi', + 'worker_threads', + 'zlib', + /^node:/, + 'pnpapi' + ], + output: { + path: '/dist', + filename: '[name].cjs', + chunkFilename: '[name].cjs', + publicPath: 'auto', + pathinfo: false, + hashFunction: 'xxhash64', + library: { + type: 'commonjs-static' + }, + assetModuleFilename: 'static/assets/[name][ext]', + webassemblyModuleFilename: 'static/wasm/[contenthash:8].module.wasm', + iife: false, + chunkFormat: 'commonjs', + chunkLoading: 'require', + workerChunkLoading: 'async-node' + }, + resolve: { + tsConfig: { + configFile: '/tsconfig.json', + references: 'auto' + }, + alias: { + '@swc/helpers': '/node_modules//@swc/helpers', + foo: 'foo', + bar: 'bar/cjs' + }, + extensionAlias: { + '.js': [ + '.js', + '.ts', + '.tsx', + '.ts', + '.tsx', + '.js', + '.jsx', + '.ts', + '.tsx' + ], + '.jsx': [ + '.jsx', + '.tsx', + '.tsx', + '.jsx' + ], + '.mjs': [ + '.mts', + '.mjs' + ], + '.cjs': [ + '.cts', + '.cjs' + ] + }, + extensions: [ + '.ts', + '.tsx', + '.mjs', + '.js', + '.jsx', + '.json' + ] + }, + module: { + parser: { + javascript: { + exportsPresence: 'error', + typeReexportsPresence: 'tolerant', + importMeta: false, + importDynamic: false, + requireResolve: false, + requireDynamic: false, + requireAsExpression: false, + worker: false + } + }, + rules: [ + /* config.module.rule('mjs') */ + { + test: /\\.m?js/, + resolve: { + fullySpecified: false + } + }, + /* config.module.rule('css') */ + { + test: /\\.css$/, + type: 'javascript/auto', + dependency: { + not: 'url' + }, + resourceQuery: { + not: [ + /[?&]raw(?:&|=|$)/, + /[?&]inline(?:&|=|$)/ + ] + }, + sideEffects: true, + use: [ + /* config.module.rule('css').use('ignore-css') */ + { + loader: '/node_modules//@rsbuild/core/dist/ignoreCssLoader.mjs' + }, + /* config.module.rule('css').use('css') */ + { + loader: '/node_modules//@rsbuild/core/compiled/css-loader/index.js', + options: { + importLoaders: 0, + modules: { + auto: true, + namedExport: false, + exportGlobals: false, + exportLocalsConvention: 'camelCase', + localIdentName: '[local]-[hash:base64:6]', + exportOnlyLocals: true + }, + sourceMap: false + } + } + ], + resolve: { + preferRelative: true + } + }, + /* config.module.rule('css-inline') */ + { + test: /\\.css$/, + type: 'javascript/auto', + resourceQuery: /[?&]inline(?:&|=|$)/, + sideEffects: true, + use: [ + /* config.module.rule('css-inline').use('css') */ + { + loader: '/node_modules//@rsbuild/core/compiled/css-loader/index.js', + options: { + importLoaders: 0, + modules: false, + sourceMap: false, + exportType: 'string' + } + } + ], + resolve: { + preferRelative: true + } + }, + /* config.module.rule('css-raw') */ + { + test: /\\.css$/, + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('js') */ + { + test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, + dependency: { + not: 'url' + }, + resourceQuery: { + not: /[?&]raw(?:&|=|$)/ + }, + parser: { + url: false + }, + include: [ + { + not: /[\\\\/]node_modules[\\\\/]/ + }, + /\\.(?:ts|tsx|jsx|mts|cts)$/ + ], + use: [ + /* config.module.rule('js').use('swc') */ + { + loader: 'builtin:swc-loader', + options: { + jsc: { + externalHelpers: false, + parser: { + tsx: false, + syntax: 'typescript', + decorators: true + }, + experimental: { + cacheRoot: '/node_modules/.cache/.swc', + keepImportAttributes: true + }, + output: { + charset: 'utf8' + }, + transform: { + legacyDecorator: false, + decoratorVersion: '2022-03' + } + }, + isModule: 'unknown', + env: { + targets: [ + 'last 1 node versions' + ] + }, + rspackExperiments: { + collectTypeScriptInfo: { + typeExports: true, + exportedEnum: true + } + } + } + } + ] + }, + /* config.module.rule('js-raw') */ + { + test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('js-data-uri') */ + { + mimetype: { + or: [ + 'text/javascript', + 'application/javascript' + ] + }, + use: [ + /* config.module.rule('js-data-uri').use('swc') */ + { + loader: 'builtin:swc-loader', + options: { + jsc: { + externalHelpers: false, + parser: { + tsx: false, + syntax: 'typescript', + decorators: true + }, + experimental: { + cacheRoot: '/node_modules/.cache/.swc', + keepImportAttributes: true + }, + output: { + charset: 'utf8' + }, + transform: { + legacyDecorator: false, + decoratorVersion: '2022-03' + } + }, + isModule: 'unknown', + env: { + targets: [ + 'last 1 node versions' + ] + }, + rspackExperiments: { + collectTypeScriptInfo: { + typeExports: true, + exportedEnum: true + } + } + } + } + ], + resolve: { + fullySpecified: false + } + }, + /* config.module.rule('image') */ + { + test: /\\.(?:png|jpg|jpeg|pjpeg|pjp|gif|bmp|webp|ico|apng|avif|tif|tiff|jfif|cur)$/i, + oneOf: [ + /* config.module.rule('image').oneOf('image-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/image/[name][ext]' + } + }, + /* config.module.rule('image').oneOf('image-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('image').oneOf('image-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('image').oneOf('image-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 0 + } + }, + generator: { + filename: 'static/image/[name][ext]', + importMode: 'preserve' + }, + issuer: { + not: /\\.(css|sass|scss|less|styl|stylus)$/ + } + }, + /* config.module.rule('image').oneOf('image-asset-for-css') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 0 + } + }, + generator: { + filename: 'static/image/[name][ext]' + }, + issuer: /\\.(css|sass|scss|less|styl|stylus)$/ + } + ] + }, + /* config.module.rule('svg') */ + { + test: /\\.svg$/i, + oneOf: [ + /* config.module.rule('svg').oneOf('svg-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/svg/[name].svg' + } + }, + /* config.module.rule('svg').oneOf('svg-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('svg').oneOf('svg-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('svg').oneOf('svg-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 0 + } + }, + generator: { + filename: 'static/svg/[name].svg', + importMode: 'preserve' + }, + issuer: { + not: /\\.(css|sass|scss|less|styl|stylus)$/ + } + }, + /* config.module.rule('svg').oneOf('svg-asset-for-css') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 0 + } + }, + generator: { + filename: 'static/svg/[name].svg' + }, + issuer: /\\.(css|sass|scss|less|styl|stylus)$/ + }, + /* config.module.rule('svg').oneOf('svg') */ + {} + ] + }, + /* config.module.rule('media') */ + { + test: /\\.(?:mp4|webm|ogg|mov|mp3|wav|flac|aac|m4a|opus)$/i, + oneOf: [ + /* config.module.rule('media').oneOf('media-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/media/[name][ext]' + } + }, + /* config.module.rule('media').oneOf('media-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('media').oneOf('media-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('media').oneOf('media-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 0 + } + }, + generator: { + filename: 'static/media/[name][ext]', + importMode: 'preserve' + }, + issuer: { + not: /\\.(css|sass|scss|less|styl|stylus)$/ + } + }, + /* config.module.rule('media').oneOf('media-asset-for-css') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 0 + } + }, + generator: { + filename: 'static/media/[name][ext]' + }, + issuer: /\\.(css|sass|scss|less|styl|stylus)$/ + } + ] + }, + /* config.module.rule('font') */ + { + test: /\\.(?:woff|woff2|eot|ttf|otf|ttc)$/i, + oneOf: [ + /* config.module.rule('font').oneOf('font-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/font/[name][ext]' + } + }, + /* config.module.rule('font').oneOf('font-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('font').oneOf('font-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('font').oneOf('font-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 0 + } + }, + generator: { + filename: 'static/font/[name][ext]', + importMode: 'preserve' + }, + issuer: { + not: /\\.(css|sass|scss|less|styl|stylus)$/ + } + }, + /* config.module.rule('font').oneOf('font-asset-for-css') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 0 + } + }, + generator: { + filename: 'static/font/[name][ext]' + }, + issuer: /\\.(css|sass|scss|less|styl|stylus)$/ + } + ] + }, + /* config.module.rule('wasm') */ + { + test: /\\.wasm$/, + dependency: 'url', + type: 'asset/resource', + generator: { + filename: 'static/wasm/[contenthash:8].module.wasm' + } + }, + /* config.module.rule('rsbuild-transform-0') */ + { + test: /\\.node$/, + use: [ + /* config.module.rule('rsbuild-transform-0').use('rsbuild-transform-0') */ + { + loader: '/node_modules//@rsbuild/core/dist/transformRawLoader.mjs', + options: { + id: 'rsbuild-transform-0', + getEnvironment: ()=>environment + } + } + ] + }, + /* config.module.rule('Rslib:js-entry-loader') */ + { + test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, + issuer: /^$/, + use: [ + /* config.module.rule('Rslib:js-entry-loader').use('rsbuild:lib-entry-module') */ + { + loader: '/dist/entryModuleLoader.js' + } + ] + } + ] + }, + optimization: { + minimize: true, + splitChunks: { + chunks: 'async' + }, + minimizer: [ + /* config.optimization.minimizer('js') */ + new SwcJsMinimizerRspackPlugin( + { + minimizerOptions: { + format: { + asciiOnly: false, + comments: 'some', + preserve_annotations: true + }, + mangle: false, + minify: false, + compress: { + defaults: false, + unused: true, + dead_code: true, + toplevel: true + } + }, + extractComments: true + } + ) + ], + moduleIds: 'named', + nodeEnv: false + }, + plugins: [ + /* config.plugin('RsbuildCorePlugin') */ + {}, + /* config.plugin('define') */ + new DefinePlugin( + { + 'import.meta.env.MODE': '"production"', + 'import.meta.env.DEV': false, + 'import.meta.env.PROD': true, + 'import.meta.env.BASE_URL': '"/"', + 'import.meta.env.ASSET_PREFIX': '"auto"', + 'process.env.BASE_URL': '"/"', + 'process.env.ASSET_PREFIX': '"auto"', + 'import.meta.url': '__rslib_import_meta_url__' + } + ), + { + affectedHooks: undefined, + name: 'RslibPlugin', + _args: [ + { + interceptApiPlugin: true + } + ] + }, + { + reactDirectives: {}, + shimsInjectedAssets: new Set([]), + shebangChmod: 493, + shebangEntries: {}, + shebangInjectedAssets: new Set([]), + enabledImportMetaUrlShim: true, + contextToWatch: null + } + ], + performance: { + hints: false + }, + entry: { + index: [ + './a.js', + './c.js', + './d.js', + '/src/index.ts' + ] + }, + externalsType: 'commonjs-import' +}", + "{ + target: [ + 'es2022', + 'node' + ], + name: 'umd', + devtool: false, + context: '', + mode: 'production', + infrastructureLogging: { + level: 'error' + }, + watchOptions: { + aggregateTimeout: 0 + }, + experiments: { + lazyBarrel: true, + inlineEnum: true, + typeReexportsPresence: true, + rspackFuture: { + bundlerInfo: { + force: false + } + }, + asyncWebAssembly: true + }, + externals: [ + 'assert', + 'assert/strict', + 'async_hooks', + 'buffer', + 'child_process', + 'cluster', + 'console', + 'constants', + 'crypto', + 'dgram', + 'diagnostics_channel', + 'dns', + 'dns/promises', + 'domain', + 'events', + 'fs', + 'fs/promises', + 'http', + 'http2', + 'https', + 'inspector', + 'inspector/promises', + 'module', + 'net', + 'os', + 'path', + 'path/posix', + 'path/win32', + 'perf_hooks', + 'process', + 'punycode', + 'querystring', + 'readline', + 'readline/promises', + 'repl', + 'stream', + 'stream/consumers', + 'stream/promises', + 'stream/web', + 'string_decoder', + 'sys', + 'timers', + 'timers/promises', + 'tls', + 'trace_events', + 'tty', + 'url', + 'util', + 'util/types', + 'v8', + 'vm', + 'wasi', + 'worker_threads', + 'zlib', + /^node:/, + 'pnpapi' + ], + output: { + path: '/dist', + filename: '[name].js', + chunkFilename: '[name].js', + publicPath: '/', + pathinfo: false, + hashFunction: 'xxhash64', + library: { + type: 'umd' + }, + assetModuleFilename: 'static/assets/[name][ext]', + webassemblyModuleFilename: 'static/wasm/[contenthash:8].module.wasm', + asyncChunks: false + }, + resolve: { + tsConfig: { + configFile: '/tsconfig.json', + references: 'auto' + }, + alias: { + '@swc/helpers': '/node_modules//@swc/helpers', + foo: 'foo', + bar: 'bar' + }, + extensionAlias: { + '.js': [ + '.js', + '.ts', + '.tsx', + '.ts', + '.tsx', + '.js', + '.jsx', + '.ts', + '.tsx' + ], + '.jsx': [ + '.jsx', + '.tsx', + '.tsx', + '.jsx' + ], + '.mjs': [ + '.mts', + '.mjs' + ], + '.cjs': [ + '.cts', + '.cjs' + ] + }, + extensions: [ + '.ts', + '.tsx', + '.mjs', + '.js', + '.jsx', + '.json' + ] + }, + module: { + parser: { + javascript: { + exportsPresence: 'error', + typeReexportsPresence: 'tolerant', + importMeta: false + } + }, + rules: [ + /* config.module.rule('mjs') */ + { + test: /\\.m?js/, + resolve: { + fullySpecified: false + } + }, + /* config.module.rule('css') */ + { + test: /\\.css$/, + type: 'javascript/auto', + dependency: { + not: 'url' + }, + resourceQuery: { + not: [ + /[?&]raw(?:&|=|$)/, + /[?&]inline(?:&|=|$)/ + ] + }, + sideEffects: true, + use: [ + /* config.module.rule('css').use('ignore-css') */ + { + loader: '/node_modules//@rsbuild/core/dist/ignoreCssLoader.mjs' + }, + /* config.module.rule('css').use('css') */ + { + loader: '/node_modules//@rsbuild/core/compiled/css-loader/index.js', + options: { + importLoaders: 0, + modules: { + auto: true, + namedExport: false, + exportGlobals: false, + exportLocalsConvention: 'camelCase', + localIdentName: '[local]-[hash:base64:6]', + exportOnlyLocals: true + }, + sourceMap: false + } + } + ], + resolve: { + preferRelative: true + } + }, + /* config.module.rule('css-inline') */ + { + test: /\\.css$/, + type: 'javascript/auto', + resourceQuery: /[?&]inline(?:&|=|$)/, + sideEffects: true, + use: [ + /* config.module.rule('css-inline').use('css') */ + { + loader: '/node_modules//@rsbuild/core/compiled/css-loader/index.js', + options: { + importLoaders: 0, + modules: false, + sourceMap: false, + exportType: 'string' + } + } + ], + resolve: { + preferRelative: true + } + }, + /* config.module.rule('css-raw') */ + { + test: /\\.css$/, + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('js') */ + { + test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, + dependency: { + not: 'url' + }, + resourceQuery: { + not: /[?&]raw(?:&|=|$)/ + }, + include: [ + { + not: /[\\\\/]node_modules[\\\\/]/ + }, + /\\.(?:ts|tsx|jsx|mts|cts)$/ + ], + use: [ + /* config.module.rule('js').use('swc') */ + { + loader: 'builtin:swc-loader', + options: { + jsc: { + externalHelpers: false, + parser: { + tsx: false, + syntax: 'typescript', + decorators: true + }, + experimental: { + cacheRoot: '/node_modules/.cache/.swc', + keepImportAttributes: true + }, + output: { + charset: 'utf8' + }, + transform: { + legacyDecorator: false, + decoratorVersion: '2022-03' + } + }, + isModule: 'unknown', + env: { + targets: [ + 'last 1 node versions' + ] + }, + rspackExperiments: { + collectTypeScriptInfo: { + typeExports: true, + exportedEnum: true + } + } + } + } + ] + }, + /* config.module.rule('js-raw') */ + { + test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('js-data-uri') */ + { + mimetype: { + or: [ + 'text/javascript', + 'application/javascript' + ] + }, + use: [ + /* config.module.rule('js-data-uri').use('swc') */ + { + loader: 'builtin:swc-loader', + options: { + jsc: { + externalHelpers: false, + parser: { + tsx: false, + syntax: 'typescript', + decorators: true + }, + experimental: { + cacheRoot: '/node_modules/.cache/.swc', + keepImportAttributes: true + }, + output: { + charset: 'utf8' + }, + transform: { + legacyDecorator: false, + decoratorVersion: '2022-03' + } + }, + isModule: 'unknown', + env: { + targets: [ + 'last 1 node versions' + ] + }, + rspackExperiments: { + collectTypeScriptInfo: { + typeExports: true, + exportedEnum: true + } + } + } + } + ], + resolve: { + fullySpecified: false + } + }, + /* config.module.rule('image') */ + { + test: /\\.(?:png|jpg|jpeg|pjpeg|pjp|gif|bmp|webp|ico|apng|avif|tif|tiff|jfif|cur)$/i, + oneOf: [ + /* config.module.rule('image').oneOf('image-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/image/[name][ext]' + } + }, + /* config.module.rule('image').oneOf('image-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('image').oneOf('image-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('image').oneOf('image-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 4096 + } + }, + generator: { + filename: 'static/image/[name][ext]' + } + } + ] + }, + /* config.module.rule('svg') */ + { + test: /\\.svg$/i, + oneOf: [ + /* config.module.rule('svg').oneOf('svg-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/svg/[name].svg' + } + }, + /* config.module.rule('svg').oneOf('svg-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('svg').oneOf('svg-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('svg').oneOf('svg-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 4096 + } + }, + generator: { + filename: 'static/svg/[name].svg' + } + } + ] + }, + /* config.module.rule('media') */ + { + test: /\\.(?:mp4|webm|ogg|mov|mp3|wav|flac|aac|m4a|opus)$/i, + oneOf: [ + /* config.module.rule('media').oneOf('media-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/media/[name][ext]' + } + }, + /* config.module.rule('media').oneOf('media-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('media').oneOf('media-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('media').oneOf('media-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 4096 + } + }, + generator: { + filename: 'static/media/[name][ext]' + } + } + ] + }, + /* config.module.rule('font') */ + { + test: /\\.(?:woff|woff2|eot|ttf|otf|ttc)$/i, + oneOf: [ + /* config.module.rule('font').oneOf('font-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/font/[name][ext]' + } + }, + /* config.module.rule('font').oneOf('font-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('font').oneOf('font-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('font').oneOf('font-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 4096 + } + }, + generator: { + filename: 'static/font/[name][ext]' + } + } + ] + }, + /* config.module.rule('wasm') */ + { + test: /\\.wasm$/, + dependency: 'url', + type: 'asset/resource', + generator: { + filename: 'static/wasm/[contenthash:8].module.wasm' + } + }, + /* config.module.rule('rsbuild-transform-0') */ + { + test: /\\.node$/, + use: [ + /* config.module.rule('rsbuild-transform-0').use('rsbuild-transform-0') */ + { + loader: '/node_modules//@rsbuild/core/dist/transformRawLoader.mjs', + options: { + id: 'rsbuild-transform-0', + getEnvironment: ()=>environment + } + } + ] + }, + /* config.module.rule('Rslib:js-entry-loader') */ + { + test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, + issuer: /^$/, + use: [ + /* config.module.rule('Rslib:js-entry-loader').use('rsbuild:lib-entry-module') */ + { + loader: '/dist/entryModuleLoader.js' + } + ] + } + ] + }, + optimization: { + minimize: true, + splitChunks: false, + minimizer: [ + /* config.optimization.minimizer('js') */ + new SwcJsMinimizerRspackPlugin( + { + minimizerOptions: { + format: { + asciiOnly: false, + comments: 'some', + preserve_annotations: true + }, + mangle: false, + minify: false, + compress: { + defaults: false, + unused: true, + dead_code: true, + toplevel: true + } + }, + extractComments: true + } + ) + ], + moduleIds: 'named', + nodeEnv: false + }, + plugins: [ + /* config.plugin('RsbuildCorePlugin') */ + {}, + /* config.plugin('define') */ + new DefinePlugin( + { + 'import.meta.env.MODE': '"production"', + 'import.meta.env.DEV': false, + 'import.meta.env.PROD': true, + 'import.meta.env.BASE_URL': '"/"', + 'import.meta.env.ASSET_PREFIX': '""', + 'process.env.BASE_URL': '"/"', + 'process.env.ASSET_PREFIX': '""' + } + ), + { + affectedHooks: undefined, + name: 'RslibPlugin', + _args: [ + { + interceptApiPlugin: true + } + ] + }, + { + reactDirectives: {}, + shimsInjectedAssets: new Set([]), + shebangChmod: 493, + shebangEntries: {}, + shebangInjectedAssets: new Set([]), + enabledImportMetaUrlShim: false, + contextToWatch: null + } + ], + performance: { + hints: false + }, + entry: { + index: [ + './a.js', + '/src/index.ts' + ] + }, + externalsType: 'umd' +}", + "{ + target: [ + 'es2022', + 'node' + ], + name: 'iife', + devtool: false, + context: '', + mode: 'production', + infrastructureLogging: { + level: 'error' + }, + watchOptions: { + aggregateTimeout: 0 + }, + experiments: { + lazyBarrel: true, + inlineEnum: true, + typeReexportsPresence: true, + rspackFuture: { + bundlerInfo: { + force: false + } + }, + asyncWebAssembly: true + }, + externals: [ + 'assert', + 'assert/strict', + 'async_hooks', + 'buffer', + 'child_process', + 'cluster', + 'console', + 'constants', + 'crypto', + 'dgram', + 'diagnostics_channel', + 'dns', + 'dns/promises', + 'domain', + 'events', + 'fs', + 'fs/promises', + 'http', + 'http2', + 'https', + 'inspector', + 'inspector/promises', + 'module', + 'net', + 'os', + 'path', + 'path/posix', + 'path/win32', + 'perf_hooks', + 'process', + 'punycode', + 'querystring', + 'readline', + 'readline/promises', + 'repl', + 'stream', + 'stream/consumers', + 'stream/promises', + 'stream/web', + 'string_decoder', + 'sys', + 'timers', + 'timers/promises', + 'tls', + 'trace_events', + 'tty', + 'url', + 'util', + 'util/types', + 'v8', + 'vm', + 'wasi', + 'worker_threads', + 'zlib', + /^node:/, + 'pnpapi' + ], + output: { + path: '/dist', + filename: '[name].js', + chunkFilename: '[name].js', + publicPath: '/', + pathinfo: false, + hashFunction: 'xxhash64', + library: { + type: 'modern-module' + }, + assetModuleFilename: 'static/assets/[name][ext]', + webassemblyModuleFilename: 'static/wasm/[contenthash:8].module.wasm', + iife: true, + asyncChunks: false, + globalObject: 'globalThis' + }, + resolve: { + tsConfig: { + configFile: '/tsconfig.json', + references: 'auto' + }, + alias: { + '@swc/helpers': '/node_modules//@swc/helpers', + foo: 'foo', + bar: 'bar' + }, + extensionAlias: { + '.js': [ + '.js', + '.ts', + '.tsx', + '.ts', + '.tsx', + '.js', + '.jsx', + '.ts', + '.tsx' + ], + '.jsx': [ + '.jsx', + '.tsx', + '.tsx', + '.jsx' + ], + '.mjs': [ + '.mts', + '.mjs' + ], + '.cjs': [ + '.cts', + '.cjs' + ] + }, + extensions: [ + '.ts', + '.tsx', + '.mjs', + '.js', + '.jsx', + '.json' + ] + }, + module: { + parser: { + javascript: { + exportsPresence: 'error', + typeReexportsPresence: 'tolerant', + importMeta: false + } + }, + rules: [ + /* config.module.rule('mjs') */ + { + test: /\\.m?js/, + resolve: { + fullySpecified: false + } + }, + /* config.module.rule('css') */ + { + test: /\\.css$/, + type: 'javascript/auto', + dependency: { + not: 'url' + }, + resourceQuery: { + not: [ + /[?&]raw(?:&|=|$)/, + /[?&]inline(?:&|=|$)/ + ] + }, + sideEffects: true, + use: [ + /* config.module.rule('css').use('ignore-css') */ + { + loader: '/node_modules//@rsbuild/core/dist/ignoreCssLoader.mjs' + }, + /* config.module.rule('css').use('css') */ + { + loader: '/node_modules//@rsbuild/core/compiled/css-loader/index.js', + options: { + importLoaders: 0, + modules: { + auto: true, + namedExport: false, + exportGlobals: false, + exportLocalsConvention: 'camelCase', + localIdentName: '[local]-[hash:base64:6]', + exportOnlyLocals: true + }, + sourceMap: false + } + } + ], + resolve: { + preferRelative: true + } + }, + /* config.module.rule('css-inline') */ + { + test: /\\.css$/, + type: 'javascript/auto', + resourceQuery: /[?&]inline(?:&|=|$)/, + sideEffects: true, + use: [ + /* config.module.rule('css-inline').use('css') */ + { + loader: '/node_modules//@rsbuild/core/compiled/css-loader/index.js', + options: { + importLoaders: 0, + modules: false, + sourceMap: false, + exportType: 'string' + } + } + ], + resolve: { + preferRelative: true + } + }, + /* config.module.rule('css-raw') */ + { + test: /\\.css$/, + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('js') */ + { + test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, + dependency: { + not: 'url' + }, + resourceQuery: { + not: /[?&]raw(?:&|=|$)/ + }, + include: [ + { + not: /[\\\\/]node_modules[\\\\/]/ + }, + /\\.(?:ts|tsx|jsx|mts|cts)$/ + ], + use: [ + /* config.module.rule('js').use('swc') */ + { + loader: 'builtin:swc-loader', + options: { + jsc: { + externalHelpers: false, + parser: { + tsx: false, + syntax: 'typescript', + decorators: true + }, + experimental: { + cacheRoot: '/node_modules/.cache/.swc', + keepImportAttributes: true + }, + output: { + charset: 'utf8' + }, + transform: { + legacyDecorator: false, + decoratorVersion: '2022-03' + } + }, + isModule: 'unknown', + env: { + targets: [ + 'last 1 node versions' + ] + }, + rspackExperiments: { + collectTypeScriptInfo: { + typeExports: true, + exportedEnum: true + } + } + } + } + ] + }, + /* config.module.rule('js-raw') */ + { + test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('js-data-uri') */ + { + mimetype: { + or: [ + 'text/javascript', + 'application/javascript' + ] + }, + use: [ + /* config.module.rule('js-data-uri').use('swc') */ + { + loader: 'builtin:swc-loader', + options: { + jsc: { + externalHelpers: false, + parser: { + tsx: false, + syntax: 'typescript', + decorators: true + }, + experimental: { + cacheRoot: '/node_modules/.cache/.swc', + keepImportAttributes: true + }, + output: { + charset: 'utf8' + }, + transform: { + legacyDecorator: false, + decoratorVersion: '2022-03' + } + }, + isModule: 'unknown', + env: { + targets: [ + 'last 1 node versions' + ] + }, + rspackExperiments: { + collectTypeScriptInfo: { + typeExports: true, + exportedEnum: true + } + } + } + } + ], + resolve: { + fullySpecified: false + } + }, + /* config.module.rule('image') */ + { + test: /\\.(?:png|jpg|jpeg|pjpeg|pjp|gif|bmp|webp|ico|apng|avif|tif|tiff|jfif|cur)$/i, + oneOf: [ + /* config.module.rule('image').oneOf('image-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/image/[name][ext]' + } + }, + /* config.module.rule('image').oneOf('image-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('image').oneOf('image-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('image').oneOf('image-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 4096 + } + }, + generator: { + filename: 'static/image/[name][ext]' + } + } + ] + }, + /* config.module.rule('svg') */ + { + test: /\\.svg$/i, + oneOf: [ + /* config.module.rule('svg').oneOf('svg-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/svg/[name].svg' + } + }, + /* config.module.rule('svg').oneOf('svg-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('svg').oneOf('svg-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('svg').oneOf('svg-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 4096 + } + }, + generator: { + filename: 'static/svg/[name].svg' + } + } + ] + }, + /* config.module.rule('media') */ + { + test: /\\.(?:mp4|webm|ogg|mov|mp3|wav|flac|aac|m4a|opus)$/i, + oneOf: [ + /* config.module.rule('media').oneOf('media-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/media/[name][ext]' + } + }, + /* config.module.rule('media').oneOf('media-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('media').oneOf('media-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('media').oneOf('media-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 4096 + } + }, + generator: { + filename: 'static/media/[name][ext]' + } + } + ] + }, + /* config.module.rule('font') */ + { + test: /\\.(?:woff|woff2|eot|ttf|otf|ttc)$/i, + oneOf: [ + /* config.module.rule('font').oneOf('font-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/font/[name][ext]' + } + }, + /* config.module.rule('font').oneOf('font-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('font').oneOf('font-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('font').oneOf('font-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 4096 + } + }, + generator: { + filename: 'static/font/[name][ext]' + } + } + ] + }, + /* config.module.rule('wasm') */ + { + test: /\\.wasm$/, + dependency: 'url', + type: 'asset/resource', + generator: { + filename: 'static/wasm/[contenthash:8].module.wasm' + } + }, + /* config.module.rule('rsbuild-transform-0') */ + { + test: /\\.node$/, + use: [ + /* config.module.rule('rsbuild-transform-0').use('rsbuild-transform-0') */ + { + loader: '/node_modules//@rsbuild/core/dist/transformRawLoader.mjs', + options: { + id: 'rsbuild-transform-0', + getEnvironment: ()=>environment + } + } + ] + }, + /* config.module.rule('Rslib:js-entry-loader') */ + { + test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, + issuer: /^$/, + use: [ + /* config.module.rule('Rslib:js-entry-loader').use('rsbuild:lib-entry-module') */ + { + loader: '/dist/entryModuleLoader.js' + } + ] + } + ] + }, + optimization: { + minimize: true, + splitChunks: false, + minimizer: [ + /* config.optimization.minimizer('js') */ + new SwcJsMinimizerRspackPlugin( + { + minimizerOptions: { + format: { + asciiOnly: false, + comments: 'some', + preserve_annotations: true + }, + module: true, + mangle: false, + minify: false, + compress: { + defaults: false, + unused: true, + dead_code: true, + toplevel: true + } + }, + extractComments: true + } + ) + ], + moduleIds: 'named', + nodeEnv: false + }, + plugins: [ + /* config.plugin('RsbuildCorePlugin') */ + {}, + /* config.plugin('define') */ + new DefinePlugin( + { + 'import.meta.env.MODE': '"production"', + 'import.meta.env.DEV': false, + 'import.meta.env.PROD': true, + 'import.meta.env.BASE_URL': '"/"', + 'import.meta.env.ASSET_PREFIX': '""', + 'process.env.BASE_URL': '"/"', + 'process.env.ASSET_PREFIX': '""' + } + ), + { + affectedHooks: undefined, + name: 'RslibPlugin', + _args: [ + { + interceptApiPlugin: true + } + ] + }, + { + reactDirectives: {}, + shimsInjectedAssets: new Set([]), + shebangChmod: 493, + shebangEntries: {}, + shebangInjectedAssets: new Set([]), + enabledImportMetaUrlShim: false, + contextToWatch: null + } + ], + performance: { + hints: false + }, + entry: { + index: [ + './a.js', + '/src/index.ts' + ] + }, + externalsType: 'global' +}", + "{ + target: [ + 'es2022', + 'web' + ], + name: 'mf', + devtool: false, + context: '', + mode: 'production', + infrastructureLogging: { + level: 'error' + }, + watchOptions: { + aggregateTimeout: 0 + }, + experiments: { + lazyBarrel: true, + inlineEnum: true, + typeReexportsPresence: true, + rspackFuture: { + bundlerInfo: { + force: false + } + }, + asyncWebAssembly: true + }, + output: { + path: '/dist', + filename: '[name].js', + chunkFilename: '[name].js', + publicPath: '/', + pathinfo: false, + hashFunction: 'xxhash64', + assetModuleFilename: 'static/assets/[name][ext]', + webassemblyModuleFilename: 'static/wasm/[contenthash:8].module.wasm', + uniqueName: '@rslib/core' + }, + resolve: { + tsConfig: { + configFile: '/tsconfig.json', + references: 'auto' + }, + alias: { + '@swc/helpers': '/node_modules//@swc/helpers', + foo: 'foo', + bar: 'bar' + }, + extensionAlias: { + '.js': [ + '.js', + '.ts', + '.tsx', + '.ts', + '.tsx', + '.js', + '.jsx', + '.ts', + '.tsx' + ], + '.jsx': [ + '.jsx', + '.tsx', + '.tsx', + '.jsx' + ], + '.mjs': [ + '.mts', + '.mjs' + ], + '.cjs': [ + '.cts', + '.cjs' + ] + }, + extensions: [ + '.ts', + '.tsx', + '.mjs', + '.js', + '.jsx', + '.json' + ] + }, + module: { + parser: { + javascript: { + exportsPresence: 'error', + typeReexportsPresence: 'tolerant' + } + }, + rules: [ + /* config.module.rule('mjs') */ + { + test: /\\.m?js/, + resolve: { + fullySpecified: false + } + }, + /* config.module.rule('css') */ + { + test: /\\.css$/, + type: 'javascript/auto', + dependency: { + not: 'url' + }, + resourceQuery: { + not: [ + /[?&]raw(?:&|=|$)/, + /[?&]inline(?:&|=|$)/ + ] + }, + sideEffects: true, + use: [ + /* config.module.rule('css').use('mini-css-extract') */ + { + loader: '/node_modules//@rspack/core/dist/cssExtractLoader.js' + }, + /* config.module.rule('css').use('css') */ + { + loader: '/node_modules//@rsbuild/core/compiled/css-loader/index.js', + options: { + importLoaders: 1, + modules: { + auto: true, + namedExport: false, + exportGlobals: false, + exportLocalsConvention: 'camelCase', + localIdentName: '[local]-[hash:base64:6]' + }, + sourceMap: false + } + }, + /* config.module.rule('css').use('lightningcss') */ + { + loader: 'builtin:lightningcss-loader', + options: { + targets: [ + 'last 1 Chrome versions', + 'last 1 Firefox versions', + 'last 1 Edge versions', + 'last 1 Safari versions', + 'last 1 ios_saf versions', + 'not dead' + ], + errorRecovery: true + } + } + ], + resolve: { + preferRelative: true + } + }, + /* config.module.rule('css-inline') */ + { + test: /\\.css$/, + type: 'javascript/auto', + resourceQuery: /[?&]inline(?:&|=|$)/, + sideEffects: true, + use: [ + /* config.module.rule('css-inline').use('css') */ + { + loader: '/node_modules//@rsbuild/core/compiled/css-loader/index.js', + options: { + importLoaders: 1, + modules: false, + sourceMap: false, + exportType: 'string' + } + }, + /* config.module.rule('css-inline').use('lightningcss') */ + { + loader: 'builtin:lightningcss-loader', + options: { + targets: [ + 'last 1 Chrome versions', + 'last 1 Firefox versions', + 'last 1 Edge versions', + 'last 1 Safari versions', + 'last 1 ios_saf versions', + 'not dead' + ], + errorRecovery: true + } + } + ], + resolve: { + preferRelative: true + } + }, + /* config.module.rule('css-raw') */ + { + test: /\\.css$/, + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('js') */ + { + test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, + dependency: { + not: 'url' + }, + resourceQuery: { + not: /[?&]raw(?:&|=|$)/ + }, + include: [ + { + not: /[\\\\/]node_modules[\\\\/]/ + }, + /\\.(?:ts|tsx|jsx|mts|cts)$/, + /@module-federation\\/webpack-bundler-runtime/, + /@module-federation\\/runtime/, + /@module-federation\\/runtime-core/, + /@module-federation\\/sdk/ + ], + use: [ + /* config.module.rule('js').use('swc') */ + { + loader: 'builtin:swc-loader', + options: { + jsc: { + externalHelpers: false, + parser: { + tsx: false, + syntax: 'typescript', + decorators: true + }, + experimental: { + cacheRoot: '/node_modules/.cache/.swc', + keepImportAttributes: true + }, + output: { + charset: 'utf8' + }, + transform: { + legacyDecorator: false, + decoratorVersion: '2022-03' + } + }, + isModule: 'unknown', + env: { + targets: [ + 'last 1 Chrome versions', + 'last 1 Firefox versions', + 'last 1 Edge versions', + 'last 1 Safari versions', + 'last 1 ios_saf versions', + 'not dead' + ], + mode: undefined + }, + rspackExperiments: { + collectTypeScriptInfo: { + typeExports: true, + exportedEnum: true + } + } + } + } + ] + }, + /* config.module.rule('js-raw') */ + { + test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('js-data-uri') */ + { + mimetype: { + or: [ + 'text/javascript', + 'application/javascript' + ] + }, + use: [ + /* config.module.rule('js-data-uri').use('swc') */ + { + loader: 'builtin:swc-loader', + options: { + jsc: { + externalHelpers: false, + parser: { + tsx: false, + syntax: 'typescript', + decorators: true + }, + experimental: { + cacheRoot: '/node_modules/.cache/.swc', + keepImportAttributes: true + }, + output: { + charset: 'utf8' + }, + transform: { + legacyDecorator: false, + decoratorVersion: '2022-03' + } + }, + isModule: 'unknown', + env: { + targets: [ + 'last 1 Chrome versions', + 'last 1 Firefox versions', + 'last 1 Edge versions', + 'last 1 Safari versions', + 'last 1 ios_saf versions', + 'not dead' + ], + mode: undefined + }, + rspackExperiments: { + collectTypeScriptInfo: { + typeExports: true, + exportedEnum: true + } + } + } + } + ], + resolve: { + fullySpecified: false + } + }, + /* config.module.rule('image') */ + { + test: /\\.(?:png|jpg|jpeg|pjpeg|pjp|gif|bmp|webp|ico|apng|avif|tif|tiff|jfif|cur)$/i, + oneOf: [ + /* config.module.rule('image').oneOf('image-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/image/[name][ext]' + } + }, + /* config.module.rule('image').oneOf('image-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('image').oneOf('image-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('image').oneOf('image-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 4096 + } + }, + generator: { + filename: 'static/image/[name][ext]' + } + } + ] + }, + /* config.module.rule('svg') */ + { + test: /\\.svg$/i, + oneOf: [ + /* config.module.rule('svg').oneOf('svg-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/svg/[name].svg' + } + }, + /* config.module.rule('svg').oneOf('svg-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('svg').oneOf('svg-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('svg').oneOf('svg-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 4096 + } + }, + generator: { + filename: 'static/svg/[name].svg' + } + } + ] + }, + /* config.module.rule('media') */ + { + test: /\\.(?:mp4|webm|ogg|mov|mp3|wav|flac|aac|m4a|opus)$/i, + oneOf: [ + /* config.module.rule('media').oneOf('media-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/media/[name][ext]' + } + }, + /* config.module.rule('media').oneOf('media-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('media').oneOf('media-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('media').oneOf('media-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 4096 + } + }, + generator: { + filename: 'static/media/[name][ext]' + } + } + ] + }, + /* config.module.rule('font') */ + { + test: /\\.(?:woff|woff2|eot|ttf|otf|ttc)$/i, + oneOf: [ + /* config.module.rule('font').oneOf('font-asset-url') */ + { + type: 'asset/resource', + resourceQuery: /^\\?(__inline=false|url)$/, + generator: { + filename: 'static/font/[name][ext]' + } + }, + /* config.module.rule('font').oneOf('font-asset-inline') */ + { + type: 'asset/inline', + resourceQuery: /[?&]inline(?:&|=|$)/ + }, + /* config.module.rule('font').oneOf('font-asset-raw') */ + { + type: 'asset/source', + resourceQuery: /[?&]raw(?:&|=|$)/ + }, + /* config.module.rule('font').oneOf('font-asset') */ + { + type: 'asset', + parser: { + dataUrlCondition: { + maxSize: 4096 + } + }, + generator: { + filename: 'static/font/[name][ext]' + } + } + ] + }, + /* config.module.rule('wasm') */ + { + test: /\\.wasm$/, + dependency: 'url', + type: 'asset/resource', + generator: { + filename: 'static/wasm/[contenthash:8].module.wasm' + } + }, + /* config.module.rule('Rslib:js-entry-loader') */ + { + test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, + issuer: /^$/, + use: [ + /* config.module.rule('Rslib:js-entry-loader').use('rsbuild:lib-entry-module') */ + { + loader: '/dist/entryModuleLoader.js' + } + ] + } + ] + }, + optimization: { + minimize: true, + splitChunks: { + chunks: 'all', + cacheGroups: {} + }, + minimizer: [ + /* config.optimization.minimizer('js') */ + new SwcJsMinimizerRspackPlugin( + { + minimizerOptions: { + format: { + asciiOnly: false, + comments: 'some', + preserve_annotations: true + }, + mangle: false, + minify: true, + compress: { + defaults: false, + unused: true, + dead_code: true, + toplevel: false + } + }, + extractComments: true + } + ) + ], + moduleIds: 'named', + nodeEnv: 'development' + }, + plugins: [ + /* config.plugin('mini-css-extract') */ + new CssExtractRspackPlugin( + { + filename: '[name].css', + chunkFilename: '[name].css', + ignoreOrder: true + } + ), + /* config.plugin('RsbuildCorePlugin') */ + {}, + /* config.plugin('define') */ + new DefinePlugin( + { + 'import.meta.env.MODE': '"production"', + 'import.meta.env.DEV': false, + 'import.meta.env.PROD': true, + 'import.meta.env.BASE_URL': '"/"', + 'import.meta.env.ASSET_PREFIX': '""', + 'process.env.BASE_URL': '"/"', + 'process.env.ASSET_PREFIX': '""' + } + ), + { + reactDirectives: {}, + shimsInjectedAssets: new Set([]), + shebangChmod: 493, + shebangEntries: {}, + shebangInjectedAssets: new Set([]), + enabledImportMetaUrlShim: false, + contextToWatch: null + } + ], + performance: { + hints: false + }, + entry: { + index: [ + './a.js', + '/src/index.ts' + ] + }, + externalsType: 'global' +}", +] +`; + exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config in each format 1`] = ` [ { @@ -121,6 +3559,10 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i "name": "rsbuild:disable-url-parse", "setup": [Function], }, + { + "name": "rsbuild:fix-js-module-type", + "setup": [Function], + }, { "name": "rsbuild:lib-asset", "pre": [ @@ -394,6 +3836,10 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i "name": "rsbuild:disable-url-parse", "setup": [Function], }, + { + "name": "rsbuild:fix-js-module-type", + "setup": [Function], + }, { "name": "rsbuild:lib-asset", "pre": [ @@ -641,6 +4087,10 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i }, }, "plugins": [ + { + "name": "rsbuild:fix-js-module-type", + "setup": [Function], + }, { "name": "rsbuild:lib-entry-chunk", "setup": [Function], @@ -703,7 +4153,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i }, }, "optimization": { - "nodeEnv": "test", + "nodeEnv": undefined, }, "output": { "asyncChunks": false, @@ -868,6 +4318,10 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i }, }, "plugins": [ + { + "name": "rsbuild:fix-js-module-type", + "setup": [Function], + }, { "name": "rsbuild:lib-entry-chunk", "setup": [Function], @@ -930,7 +4384,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i }, }, "optimization": { - "nodeEnv": "test", + "nodeEnv": undefined, }, "output": { "asyncChunks": false, @@ -1048,6 +4502,10 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i }, }, "plugins": [ + { + "name": "rsbuild:fix-js-module-type", + "setup": [Function], + }, { "name": "rsbuild:lib-entry-chunk", "setup": [Function], diff --git a/packages/core/tests/config.test.ts b/packages/core/tests/config.test.ts index 22f72cb29..eef1ecb65 100644 --- a/packages/core/tests/config.test.ts +++ b/packages/core/tests/config.test.ts @@ -1,5 +1,6 @@ import { join } from 'node:path'; import { pluginModuleFederation } from '@module-federation/rsbuild-plugin'; +import { inspect } from '@rslib/core'; import { describe, expect, rs, test } from '@rstest/core'; import { composeCreateRsbuildConfig, @@ -209,6 +210,12 @@ describe('Should compose create Rsbuild config correctly', () => { }; const composedRsbuildConfig = await composeCreateRsbuildConfig(rslibConfig); expect(composedRsbuildConfig).toMatchSnapshot(); + + const rsbuildInstance = await inspect(rslibConfig); + const { rsbuildConfig, bundlerConfigs } = + await rsbuildInstance.inspectConfig(); + expect(rsbuildConfig).toMatchSnapshot('inspected Rsbuild configs'); + expect(bundlerConfigs).toMatchSnapshot('inspected Rspack configs'); }); }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c49cc70eb..b14255678 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -367,6 +367,9 @@ importers: memfs: specifier: ^4.38.1 version: 4.38.1 + path-serializer: + specifier: 0.5.1 + version: 0.5.1 picocolors: specifier: 1.1.1 version: 1.1.1 @@ -852,6 +855,8 @@ importers: tests/integration/format/default: {} + tests/integration/format/esm-interop: {} + tests/integration/format/import-meta-url: {} tests/integration/format/mf-bundle-false: {} diff --git a/tests/integration/format/esm-interop/package.json b/tests/integration/format/esm-interop/package.json new file mode 100644 index 000000000..f3e317ab8 --- /dev/null +++ b/tests/integration/format/esm-interop/package.json @@ -0,0 +1,6 @@ +{ + "name": "format-esm-interop-test", + "version": "1.0.0", + "private": true, + "type": "module" +} diff --git a/tests/integration/format/esm-interop/rslib.config.ts b/tests/integration/format/esm-interop/rslib.config.ts new file mode 100644 index 000000000..dfa79f8c1 --- /dev/null +++ b/tests/integration/format/esm-interop/rslib.config.ts @@ -0,0 +1,6 @@ +import { defineConfig } from '@rslib/core'; +import { generateBundleCjsConfig } from 'test-helper'; + +export default defineConfig({ + lib: [generateBundleCjsConfig()], +}); diff --git a/tests/integration/format/esm-interop/src/index.js b/tests/integration/format/esm-interop/src/index.js new file mode 100644 index 000000000..b3e1af1dd --- /dev/null +++ b/tests/integration/format/esm-interop/src/index.js @@ -0,0 +1,5 @@ +import * as path from 'path'; + +export const path1 = path['default']; +const _path = path; +export const path2 = _path['default']; diff --git a/tests/integration/format/index.test.ts b/tests/integration/format/index.test.ts index 7d9882d84..9ab0d6267 100644 --- a/tests/integration/format/index.test.ts +++ b/tests/integration/format/index.test.ts @@ -136,3 +136,14 @@ test("API plugin's api should be skipped in parser", async () => { expect(entries.cjs).toContain('const e = require.include;'); expect(entries.cjs).toContain('const f = require.onError;'); }); + +test('ESM interop should be correct', async () => { + const fixturePath = path.resolve(__dirname, 'esm-interop'); + const { entryFiles } = await buildAndGetResults({ + fixturePath, + }); + + const cjsOutput = await import(entryFiles.cjs); + expect(typeof cjsOutput.default.path1.basename).toBe('function'); + expect(cjsOutput.default.path1).toBe(cjsOutput.default.path2); +});