I have created an component in angular2, now I need to convert the components to npm library so that it can be installed via
npm install
I have installed angular CLI for creating the component, I have searched web I can't able to find a clear-cut instructions in converting the components to npm library, please guide me to the process of achieving it
1 . Read the NPM publishing documentation here: https://docs.npmjs.com/misc/developers
2 . Create your app as normal angular application (even using angular cli) then in your package.json file create a files entry containing only the files or directories that you want users to install with npm. (that should exclude your main angular module and only export component, services, directives e.t.c)
"files": [
"README.md",
"index.js",
"index.ts",
"src/app/component-folder/*"
],
3 . In your package.json again create a main key with your entry file (entry file should export you functions, take care not to exclude the .js version from version control.
"main": "index.js"
3 .1 Sample entry .ts file
export * from './src/app/component-name/component.module';
export * from './src/app/component-name/app.component';
export * from './src/app/component-name/app.service';
You can test before publishing to npm by creating a tar file and npm installing to your other app
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With