Modern.js supports setting the browserslist for your web applications. You can set the value of Browserslist in the .browserslistrc
file.
When you create a new Modern.js project, it will includes a .browserslistrc
configuration by default, which means that the JavaScript code will be compiled to ES6.
Please refer to Rsbuild - Browserslist for more information.
Modern.js defaults to importing corresponding polyfill code from [core-js] (https://github.com/zloirock/core-js) during compilation.
By default, the required Polyfill code will be introduced according to the settings of the Browserslist, so there is no need to worry about the Polyfill problem of the project source code and third-party dependencies, but because it contains some Polyfill code that is not used, the final bundle size may be increased.
For case where Polyfill is not required for third-party dependencies, you can set 'output.polyfill' to usage
, so that Babel compiles only Polyfill code based on the syntax used in the code.
Modern.js also provides a runtime Polyfill solution based on browser UA information, which has the following advantages over Babel:
exec pnpm run new
to enable this features:
After executing the command, register the Polyfill plugin in modern.config.ts
:
After configuring output.polyfill
as ua
and executing pnpm run build & & pnpm run serve
to start the server, visiting the page can see that the HTML artifacts contains the following script:
Visit the page http://localhost:8080/__polyfill__
on Chrome 51 to see:
This feature only works when using Modern.js built-in Web Server.
If you need to customize the HTML template, please refer to HTML Template. Manually modifying the template through html.template / tools.html will cause this feature not work.