Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import Bootstrap in Astro

I am currently working on Astro (astro.build) and would like to use it with the latest Bootstrap version.

Does anyone know about Astro and can please explain to me how to properly integrate Bootstrap?

Didn't find anything on the internet or here in the forum, at least there wasn't a clear answer.

Thank you very much!

like image 348
Andreas Avatar asked Apr 20 '26 13:04

Andreas


2 Answers

For npm/yarn:

index.astro

---
import "bootstrap/dist/css/bootstrap.min.css";
import bootstrap from "bootstrap/dist/js/bootstrap.bundle.min.js?url";
---
<html>
<script src={bootstrap}></script>
<!-- Your page here -->
</html>
like image 183
maker3 Avatar answered Apr 23 '26 08:04

maker3


I kept getting Typescript errors <script> uses an expression for the src attribute and will be ignored. and switched to Astro's suggested CSS and JS implementation using import.

# install via npm
npm install bootstrap@latest

and then use import in your .astro file

---
// Astro will bundle and optimize this automatically
import "bootstrap/dist/css/bootstrap.min.css";
---

<html>
  <!-- Your page here -->
</html>

<script>
  // Astro will bundle and process this automatically
  import 'bootstrap/dist/js/bootstrap.bundle.min.js'
</script>
like image 43
ow3n Avatar answered Apr 23 '26 06:04

ow3n



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!