DEV Community

Discussion on: What's the difference between a library and a framework?

Collapse
 
iamschulz profile image
Daniel Schulz

I agree with your example. A framework is the basis for a project (think create-react-app), a library is bolted on top (e.g. jQuery).

It gets interesting with petite-vue, which provides a bolt-on solution for framework-like features. Not sure how to categorize that.

Collapse
 
peerreynders profile image
peerreynders
<script type="module">
  import { createApp } from 'https://unpkg.com/petite-vue?module'

  function Counter(props) {
    return {
      count: props.initialCount,
      inc() {
        this.count++
      },
      mounted() {
        console.log(`I'm mounted!`)
      }
    }
  }

  createApp({
    Counter
  }).mount()
</script>
Enter fullscreen mode Exit fullscreen mode

This starts it effectively making it the "main program"

  createApp({
    Counter
  }).mount()
Enter fullscreen mode Exit fullscreen mode

This is user code that is called by it

  function Counter(props) {
    return {
      count: props.initialCount,
      inc() {
        this.count++
      },
      mounted() {
        console.log(`I'm mounted!`)
      }
    }
  }
Enter fullscreen mode Exit fullscreen mode
  • If your code calls it, it's a library.
  • If it calls your code, it's a framework.

therefore it (petite-vue) is a framework.