This project is compatible with any project that can insert JavaScript into the DOM.
- Basic understanding of class and prototype, specifically what an instance is
- Familiarity with using import and export statements
- Basic knowledge of Vite.js
- Clone this project into your repository
- Rename the folder for your convenience
- Link the generated bundle.umd.js file where you include your JavaScript files in your project
- Create your component in the components folder
- Add the import and export statements in modules.ts.
- Assign a target property to your Counter object to specify where you want to insert your component, for example:
target: document.querySelector('#Counter')
. - Create a
props
object and add it to your Counter object - Instantiate your component in your legacy code as shown:
var counter = new Component.Counter();
and pass the final object containing both the target property and theprops
object as parameters tonew Component.Counter();
.
var counter = new Component.Counter({
target: document.querySelector('#Counter'),
props: {
label: "Text from server side"
}
})
Modifications may be necessary to enable hot reloading with npm run dev
. These changes can be made in vite.config.ts
.
Feel free to add other examples in different languages and more complex use cases, and remember to add a star to this project if you find it useful.