Modern.js Builder provides a lightweight CLI tool that includes basic commands such as dev
and build
. It is primarily used for building non-React projects.
You need to install two packages:
@modern-js/builder-cli
: the CLI tool for Builder, providing basic CLI commands and automatically loading the installed Provider in the current project.@modern-js/builder-rspack-provider
: To provide the building capabilities based on Rspack.if you want to use webpack instead of Rspack, you can replace the @modern-js/builder-rspack-provider
with @modern-js/builder-webpack-provider
:
Builder CLI provides the following commands to help you quickly start a development server, build production-ready code, and more.
The builder dev
command is used to start a local development server and compile the source code in the development environment.
The builder build
command will build the outputs for production in the dist/
directory by default.
The builder serve
command is used to preview the production build outputs locally. Note that you need to execute the builder build
command beforehand to generate the corresponding outputs.
Builder CLI will read the builder.config.ts
configuration file located in the root directory of your project by default. You can use all the configuration options provided by Builder in the configuration file.
When you use Rspack as the bundler, there are some differences in configuration types between webpack and Rspack. Therefore, you need to specify the 'rspack'
generic for defineConfig
:
By default, Builder CLI uses src/index.(js|ts|jsx|tsx)
as the build entry. You can modify the build entry using the source.entries
configuration option.
You can register Builder plugins using the builderPlugins
option in builder.config.ts
.
For example, to register a Vue plugin: