27 Jul, 2019 Root User

I had written a fileuploader plugin a year back while doing my job in a company. I have been using that plugin almost in every projects to handle file upload. That was not easy task to write a js plugin because you have to write your html inside js, updating DOM is another challenging task in core js. At that time I didn't have any idea of npm to publish your plugin so that you can use it. So, now things has become so easy, anyone can easily write their own plugin and can easily share his plugin among the community. let's get started.

1. Create a fresh laravel app (I am a great laravel fan, So I am comfortable with laravel you can use vue cli or any vue project setup) and install npm dependencies and setup the projects.

2. create a folder named plugin  inside that create a js file named plugin.js

import FileUploader from './components/FileUploader'

// This is your plugin object. It can be exported to be used anywhere. export default { // The install method is all that needs to exist on the plugin object. // It takes the global Vue object as well as user-defined options. install(Vue, options) { Vue.component('file-uploader',FileUploader) } };

export {FileUploader};

During your development you can import your plugin as

import FileUploader from '../plugin/plugin.js'; 
export default { 
    components:{ FileUploader } 

Create a acount on https://www.npmjs.com and go to your plugin directory and create a npm project 

npm init

Login to your account

npm login

Publish your project as

npm publish

Profile Image

Prosperous Nepal is possible only from technological innovation.

© 2021, All right reserved.