string | string[]
undefined
Add a script before the entry file of each page. This script will be executed before the page code. Use this to execute global logic, such as injecting polyfills, setting global styles, etc.
First create a src/polyfill.ts
file:
Then configure src/polyfill.ts
to source.preEntry
:
Re-run the compilation and visit any page. You can see that the code in src/polyfill.ts
has been executed, and I am a polyfill
is logged in the console.
You can also configure global styles using source.preEntry
. This CSS code will be loaded earlier than the page code, such as introducing a normalize.css
file:
You can add multiple scripts by setting preEntry
to an array, and they will be executed in array order: