This section describes some of the core methods provided by Builder.
Create a Builder instance object.
When using this method, it needs to be used with the @modern-js/builder-webpack-provider
or @modern-js/builder-rspack-provider
. Providers implements corresponding build feature based on specific bundlers.
When builderWebpackProvider
is passed, the Builder will use webpack as the bundler for building.
When builderRspackProvider
is passed, the Builder will use Rspack as the bundler for building.
The second parameter of createBuilder
is a options object, you can pass in the following options:
Description:
cwd
: The root path of the current build, the default value is process.cwd()
.entry
: Build entry object.target
: Build target type, the default value is ['web']
, see chapter Build Target for details.framework
: The name of the framework, a unique identifier, the default value is 'modern.js'
.configPath
: The path to the framework config file (absolute path), this parameter affects the build cache update.Merges multiple Builder config objects and returns a new merged object.
This method does not modify the original config object.
A webpack object for consuming webpack builtin plugins or type definitions.
In most scenarios, it is recommended to import webpack from Builder instead of manually installing a "webpack" dependency, which can avoid multi-instance problems.
HtmlWebpackPlugin object, usually used to implement custom plugins of HtmlWebpackPlugin.
In most scenarios, it is recommended to import HtmlWebpackPlugin from builder instead of manually installing a "html-webpack-plugin" dependency, which can avoid multi-instance problems.