This section describes some dev configurations in Modern.js Builder.
boolean | string
'/'
Set the URL prefix of static assets in the development environment.
assetPrefix
will affect the URLs of most of the static assets, including JavaScript files, CSS files, images, videos, etc. If an incorrect value is specified, you'll receive 404 errors while loading these resources.
This config is only used in the development environment. In the production environment, please use the output.assetPrefix
to set the URL prefix.
If assetPrefix
is set to true
, the URL prefix will be http://localhost:port/
:
The script URL will be:
If assetPrefix
is set to false
or not set, /
is used as the default value.
When the value of assetPrefix
is string
type, the string will be used as the URL prefix:
The script URL will be:
dev.assetPrefix
corresponds to the following native configurations:
The differences from the native configuration are as follows:
dev.assetPrefix
only takes effect in the development environment.
dev.assetPrefix
automatically appends a trailing /
by default.
The value of dev.assetPrefix
is written to the process.env.ASSET_PREFIX
environment variable.
() => Promise<void> | void
undefined
dev.beforeStartUrl
is used to execute a callback function before opening the startUrl
, this config needs to be used together with dev.startUrl
.
boolean
true
Whether to enable Hot Module Replacement.
If hmr
is set to false
, the HMR and react-refresh will no longer work.
string
0.0.0.0
Specify the host that the dev server listens to.
By default, the dev server will listen to 0.0.0.0
, which means listening to all network interfaces, including localhost
and public network addresses.
If you want the dev server to listen only on localhost
, you can set it to:
boolean | { key: string; cert: string }
false
After configuring this option, you can enable HTTPS Dev Server, and disabling the HTTP Dev Server.
HTTP:
HTTPS:
You can directly set https
to true
, Builder will automatically generate the HTTPS certificate based on devcert.
When using this method, you need to manually install the devcert dependency in your project:
Then configure dev.https
to true
:
The devcert has some limitations, it does not currently support IP addresses yet.
The https proxy automatically installs the certificate and needs root authority, please enter the password according to the prompt.The password is only used to trust the certificate, and will not be leaked or be used elsewhere.
You can also manually pass in the certificate and the private key required in the dev.https
option. This parameter will be directly passed to the createServer method of the https module in Node.js.
For details, please refer to https.createServer.
number
8080
Specify a port number for Dev Server to listen.
By default, Dev Server listens on port 8080
and automatically increments the port number when the port is occupied.
Set the port to 3000
:
true
Whether to display progress bar during compilation.
If you need to modify the text displayed on the left side of the progress bar, you can set the id
option:
boolean | string | string[] | undefined
undefined
dev.startUrl
is used to set the URL of the page that automatically opens in the browser when Dev Server starts.
By default, no page will be opened.
You can set it to the following values:
Since the port number may change, you can use the <port>
placeholder to refer to the current port number, and Builder will automatically replace the placeholder with the actual listening port number.
On MacOS, you can open the specified browser when Dev Server starts, by set environment variable BROWSER
, support values: