Within the plugins
directory is a startupScripts
directory. This directory can contain JavaScript files that are executed when the app is loaded. These files will be bundled into a separate startupScripts.bundle.[hash].js file using Webpack.
To add a new startup script follow these steps:
- Create a new JavaScript file in the
/plugins/startupScripts
directory. - Write your code in the JavaScript file.
- Make sure that your code exports a function that will be executed when the app is loaded.
- Save the JavaScript file.
To build Webpack and include startup scripts, follow these steps:
- Add your startupScripts as an entry point in your Webpack configuration:
entry: {
startupScripts: glob.sync('./plugins/startupScripts/*.js'),
main: './src/index.js',
}
- Open the terminal.
- Navigate to the project directory.
- Run the command
npm run build
. - Webpack will bundle the app into the dist/web directory.
startupScripts
will be included in the startupScripts.bundle.[hash].js file.