Skip to content

Conversation

fi3ework
Copy link
Member

@fi3ework fi3ework commented Sep 29, 2025

Summary

Support more CLI options for build command, which have a higher priority than the fields in the config file.

Note that not all configuratios will be exposed via the CLI, as some can be structurally complex.

In the next phase, we plan to remove the requirement for a configuration file entirely, allowing builds to be performed purely through CLI parameters. For example: rslib build --format=cjs --dist-path=dist/cjs.

Usage:
  $ rslib build

Options:
  -w, --watch            turn on watch mode, watch for changes and rebuild
  --entry <entry>        set entry file or pattern (repeatable)
  --dist-path <dir>      set output directory
  --bundle               enable bundle mode (use --no-bundle to disable)
  --format <format>      specify the output format (esm | cjs | umd | mf | iife)
  --syntax <syntax>      set build syntax target (repeatable)
  --target <target>      set runtime target (web | node)
  --dts                  emit declaration files (use --no-dts to disable)
  --externals <pkg>      add package to externals (repeatable)
  --minify               minify output (use --no-minify to disable)
  --clean                clean output directory before build (use --no-clean to disable)
  --auto-extension       control automatic extension redirect (use --no-auto-extension to disable)
  --auto-external        control automatic dependency externalization (use --no-auto-external to disable)
  --tsconfig <path>      use specific tsconfig (relative to project root)

Options table

Click to expand

Top-level RslibConfig

Config path CLI param(s)
mode
root -r, --root <root>
logLevel --log-level <level>
dev
server
source
output
security
performance
moduleFederation
plugins
environments
provider
_privateMeta
lib --lib <id> (repeatable filter)

Shared environment options (top-level & lib[])

Source

Config path CLI param(s)
source / lib[].source
source.alias / lib[].source.alias
source.aliasStrategy / lib[].source.aliasStrategy
source.assetsInclude / lib[].source.assetsInclude
source.include / lib[].source.include
source.entry / lib[].source.entry --entry <name=path> (per lib, repeatable)
source.exclude / lib[].source.exclude
source.preEntry / lib[].source.preEntry
source.define / lib[].source.define
source.decorators / lib[].source.decorators
source.decorators.version / lib[].source.decorators.version
source.transformImport / lib[].source.transformImport
source.tsconfigPath / lib[].source.tsconfigPath --tsconfig <path> (per lib)

Dev

Config path CLI param(s)
dev / lib[].dev
dev.browserLogs / lib[].dev.browserLogs
dev.hmr / lib[].dev.hmr
dev.liveReload / lib[].dev.liveReload
dev.assetPrefix / lib[].dev.assetPrefix
dev.progressBar / lib[].dev.progressBar
dev.client / lib[].dev.client
dev.client.path / lib[].dev.client.path
dev.client.port / lib[].dev.client.port
dev.client.host / lib[].dev.client.host
dev.client.protocol / lib[].dev.client.protocol
dev.client.reconnect / lib[].dev.client.reconnect
dev.client.overlay / lib[].dev.client.overlay
dev.cliShortcuts / lib[].dev.cliShortcuts
dev.cliShortcuts.custom / lib[].dev.cliShortcuts.custom
dev.cliShortcuts.help / lib[].dev.cliShortcuts.help
dev.setupMiddlewares / lib[].dev.setupMiddlewares
dev.writeToDisk / lib[].dev.writeToDisk
dev.watchFiles / lib[].dev.watchFiles
dev.lazyCompilation / lib[].dev.lazyCompilation

Server

Config path CLI param(s)
server / lib[].server
server.base / lib[].server.base
server.compress / lib[].server.compress
server.publicDir / lib[].server.publicDir
server.port / lib[].server.port
server.https / lib[].server.https
server.host / lib[].server.host
server.headers / lib[].server.headers
server.htmlFallback / lib[].server.htmlFallback
server.historyApiFallback / lib[].server.historyApiFallback
server.open / lib[].server.open
server.cors / lib[].server.cors
server.proxy / lib[].server.proxy
server.strictPort / lib[].server.strictPort
server.printUrls / lib[].server.printUrls
server.middlewareMode / lib[].server.middlewareMode

Resolve

Config path CLI param(s)
resolve / lib[].resolve
resolve.dedupe / lib[].resolve.dedupe
resolve.alias / lib[].resolve.alias
resolve.aliasStrategy / lib[].resolve.aliasStrategy
resolve.extensions / lib[].resolve.extensions
resolve.conditionNames / lib[].resolve.conditionNames
resolve.mainFields / lib[].resolve.mainFields

Output

Config path CLI param(s)
output / lib[].output
output.target / lib[].output.target --target <target>
output.externals / lib[].output.externals --externals <pkg> (repeatable)
output.distPath / lib[].output.distPath
output.distPath.root / lib[].output.distPath.root --dist-path <dir>
output.distPath.js / lib[].output.distPath.js
output.distPath.jsAsync / lib[].output.distPath.jsAsync
output.distPath.css / lib[].output.distPath.css
output.distPath.cssAsync / lib[].output.distPath.cssAsync
output.distPath.svg / lib[].output.distPath.svg
output.distPath.font / lib[].output.distPath.font
output.distPath.html / lib[].output.distPath.html
output.distPath.wasm / lib[].output.distPath.wasm
output.distPath.image / lib[].output.distPath.image
output.distPath.media / lib[].output.distPath.media
output.distPath.assets / lib[].output.distPath.assets
output.distPath.favicon / lib[].output.distPath.favicon
output.filename / lib[].output.filename
output.filename.html / lib[].output.filename.html
output.filename.js / lib[].output.filename.js
output.filename.css / lib[].output.filename.css
output.filename.svg / lib[].output.filename.svg
output.filename.font / lib[].output.filename.font
output.filename.image / lib[].output.filename.image
output.filename.media / lib[].output.filename.media
output.filename.wasm / lib[].output.filename.wasm
output.filename.assets / lib[].output.filename.assets
output.charset / lib[].output.charset
output.polyfill / lib[].output.polyfill
output.assetPrefix / lib[].output.assetPrefix
output.dataUriLimit / lib[].output.dataUriLimit
output.dataUriLimit.svg / lib[].output.dataUriLimit.svg
output.dataUriLimit.font / lib[].output.dataUriLimit.font
output.dataUriLimit.image / lib[].output.dataUriLimit.image
output.dataUriLimit.media / lib[].output.dataUriLimit.media
output.dataUriLimit.assets / lib[].output.dataUriLimit.assets
output.legalComments / lib[].output.legalComments
output.cleanDistPath / lib[].output.cleanDistPath --clean / --no-clean
output.cssModules / lib[].output.cssModules
output.cssModules.auto / lib[].output.cssModules.auto
output.cssModules.exportGlobals / lib[].output.cssModules.exportGlobals
output.cssModules.exportLocalsConvention / lib[].output.cssModules.exportLocalsConvention
output.cssModules.namedExport / lib[].output.cssModules.namedExport
output.cssModules.localIdentName / lib[].output.cssModules.localIdentName
output.cssModules.mode / lib[].output.cssModules.mode
output.minify / lib[].output.minify --minify / --no-minify
output.manifest / lib[].output.manifest
output.module / lib[].output.module
output.sourceMap / lib[].output.sourceMap
output.sourceMap.js / lib[].output.sourceMap.js
output.sourceMap.css / lib[].output.sourceMap.css
output.filenameHash / lib[].output.filenameHash
output.inlineScripts / lib[].output.inlineScripts
output.inlineStyles / lib[].output.inlineStyles
output.injectStyles / lib[].output.injectStyles
output.overrideBrowserslist / lib[].output.overrideBrowserslist
output.copy / lib[].output.copy
output.emitAssets / lib[].output.emitAssets
output.emitCss / lib[].output.emitCss

HTML

Config path CLI param(s)
html / lib[].html
html.meta / lib[].html.meta
html.title / lib[].html.title
html.inject / lib[].html.inject
html.tags / lib[].html.tags
html.favicon / lib[].html.favicon
html.appIcon / lib[].html.appIcon
html.appIcon.name / lib[].html.appIcon.name
html.appIcon.icons / lib[].html.appIcon.icons
html.mountId / lib[].html.mountId
html.crossorigin / lib[].html.crossorigin
html.outputStructure / lib[].html.outputStructure
html.template / lib[].html.template
html.templateParameters / lib[].html.templateParameters
html.scriptLoading / lib[].html.scriptLoading

Tools

Config path CLI param(s)
tools / lib[].tools
tools.bundlerChain / lib[].tools.bundlerChain
tools.cssLoader / lib[].tools.cssLoader
tools.postcss / lib[].tools.postcss
tools.styleLoader / lib[].tools.styleLoader
tools.htmlPlugin / lib[].tools.htmlPlugin
tools.swc / lib[].tools.swc
tools.lightningcssLoader / lib[].tools.lightningcssLoader
tools.cssExtract / lib[].tools.cssExtract
tools.rspack / lib[].tools.rspack
tools.webpack / lib[].tools.webpack
tools.webpackChain / lib[].tools.webpackChain

Security

Config path CLI param(s)
security / lib[].security
security.nonce / lib[].security.nonce
security.sri / lib[].security.sri
security.sri.algorithm / lib[].security.sri.algorithm
security.sri.enable / lib[].security.sri.enable

Performance

Config path CLI param(s)
performance / lib[].performance
performance.removeConsole / lib[].performance.removeConsole
performance.removeMomentLocale / lib[].performance.removeMomentLocale
performance.buildCache / lib[].performance.buildCache
performance.printFileSize / lib[].performance.printFileSize
performance.chunkSplit / lib[].performance.chunkSplit
performance.bundleAnalyze / lib[].performance.bundleAnalyze
performance.preconnect / lib[].performance.preconnect
performance.dnsPrefetch / lib[].performance.dnsPrefetch
performance.preload / lib[].performance.preload
performance.prefetch / lib[].performance.prefetch
performance.profile / lib[].performance.profile

Module Federation & Plugins

Config path CLI param(s)
moduleFederation / lib[].moduleFederation
moduleFederation.options / lib[].moduleFederation.options
plugins / lib[].plugins

lib[] options unique to Rslib

Config path CLI param(s)
lib[].id
lib[].format --format <format>
lib[].bundle --bundle / --no-bundle
lib[].autoExtension --auto-extension / --no-auto-extension
lib[].autoExternal --auto-external / --no-auto-external
lib[].autoExternal.dependencies
lib[].autoExternal.optionalDependencies
lib[].autoExternal.peerDependencies
lib[].autoExternal.devDependencies
lib[].redirect
lib[].redirect.js
lib[].redirect.js.path
lib[].redirect.js.extension
lib[].redirect.style
lib[].redirect.style.path
lib[].redirect.style.extension
lib[].redirect.asset
lib[].redirect.asset.path
lib[].redirect.asset.extension
lib[].redirect.dts
lib[].redirect.dts.path
lib[].redirect.dts.extension
lib[].syntax --syntax <value|json>
lib[].externalHelpers
lib[].banner
lib[].banner.js
lib[].banner.css
lib[].banner.dts
lib[].footer
lib[].footer.js
lib[].footer.css
lib[].footer.dts
lib[].shims
lib[].shims.cjs
lib[].shims.cjs['import.meta.url']
lib[].shims.esm
lib[].shims.esm.__filename
lib[].shims.esm.__dirname
lib[].shims.esm.require
lib[].dts --dts / --no-dts
lib[].dts.bundle
lib[].dts.bundle.bundledPackages
lib[].dts.distPath
lib[].dts.build
lib[].dts.abortOnError
lib[].dts.autoExtension
lib[].dts.alias
lib[].dts.tsgo
lib[].umdName
lib[].outBase

Related Links

close: #454

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@Copilot Copilot AI review requested due to automatic review settings September 29, 2025 15:15
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive CLI option support for the rslib build command, allowing users to override config file settings through command line parameters. The feature supports commonly used build options like format, entry points, output directory, bundling mode, and other build configurations.

Key changes:

  • Added extensive CLI option parsing for build command parameters
  • Implemented option overriding functionality that applies CLI values over config file settings
  • Updated documentation to reflect new CLI capabilities

Reviewed Changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/core/src/cli/initConfig.ts New module implementing CLI option parsing and config merging logic
packages/core/src/cli/commands.ts Added CLI option definitions and updated command handlers to use new config system
packages/core/src/cli/init.ts Removed original init function (replaced by initConfig)
tests/integration/cli/build/build.test.ts Added comprehensive tests for CLI option functionality
tests/scripts/shared.ts Enhanced test utilities with config extraction and better error handling
website/docs/*/guide/basic/cli.mdx Updated documentation with new CLI options for both English and Chinese
packages/core/tests/config.test.ts Added unit tests for CLI option application
packages/core/tests/cli.test.ts Added unit tests for option parsing functions
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

netlify bot commented Sep 29, 2025

Deploy Preview for rslib ready!

Name Link
🔨 Latest commit a330298
🔍 Latest deploy log https://app.netlify.com/projects/rslib/deploys/68f1dea4095ad70008587b85
😎 Deploy Preview https://deploy-preview-1258--rslib.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@fi3ework fi3ework force-pushed the op branch 3 times, most recently from b4e70c7 to 2deb738 Compare September 29, 2025 15:35
@fi3ework fi3ework marked this pull request as draft October 14, 2025 12:54
@fi3ework fi3ework force-pushed the op branch 4 times, most recently from 72d4d03 to 9c9b4b0 Compare October 15, 2025 03:12
@fi3ework fi3ework marked this pull request as ready for review October 15, 2025 03:12
@fi3ework fi3ework force-pushed the op branch 4 times, most recently from 1b31856 to 6e60e06 Compare October 15, 2025 08:55
@fi3ework fi3ework requested a review from Timeless0911 October 15, 2025 09:03
@fi3ework fi3ework force-pushed the op branch 2 times, most recently from 48648b9 to f342082 Compare October 16, 2025 03:10
@Timeless0911 Timeless0911 changed the title feat: support more param for build command feat: support more cli options for build command Oct 16, 2025
@Timeless0911
Copy link
Contributor

https://rslib.rs/guide/basic/cli#rslib-build I think we should also update cli options here.

11

11

1

doc

thank u win32.

doc
@fi3ework fi3ework force-pushed the op branch 3 times, most recently from a151025 to 25faba7 Compare October 16, 2025 12:22
@fi3ework fi3ework force-pushed the op branch 3 times, most recently from 15a37c3 to 78ac3c2 Compare October 17, 2025 05:58
@Timeless0911 Timeless0911 merged commit f274031 into main Oct 17, 2025
20 checks passed
@Timeless0911 Timeless0911 deleted the op branch October 17, 2025 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Support specify more config of build command

2 participants