For example you want to create custom codes/js for a map page.
Edit the vite.config.js file under vite-wp folder, add your new file as entry point under rollupOptions input.
export default defineConfig({
build: {
manifest: true,
rollupOptions: {
input: {
critical: 'src/critical.js',
main: 'src/main.js',
// add your additional entry points here
map: 'src/components/map.js',
},
},
},
})
Load the script in wp using the FF\Vite\load_asset function.
Execute the npm run dev command and you should be able to see your script loaded
FF\Vite\load_asset('src/components/map/map.js');
After you are done with coding and want to upload for production, Execute the command npm run build
This will compile and output the optimized codes (minified, combined). The files will be saved on the dist folder. You don’t need to do anything else to load the bundled version on wp, this is already done automatically under the hood.
Select your desired option below to share a direct link to this page.
Your friends or family will thank you later.