12 September 2021

Create and Publish Library in Angular 2+ (very basic - NPM)

 

Create > build > adduser npm > publish
2021 Library Angular 2+ 
Step 1:
ng new my-workspace --create-application=false
cd my-workspace
ng generate library my-lib

Step 2:
ng build my-lib --prod
or
ng build --configuration production

Step 3:
npm adduser
(Enter username, password, email) => Verify email

Step 4:
ng build my-lib
cd dist/my-lib
npm publish
or with Ivy
npm publish --ignore-scripts

NOTE: remove version
npm unpublish ngx-xxx@1.0.18 --f
npm i github:id1945/<repository_name>#<branch_name> --save
{"ngx-abc": "github:id1945/test-002#master"}

NG 6
ng new application-name

cd application-name

ng generate library test-library --prefix=tl

ng build my-library
ng build --prod my-library

ng generate component component-name --project-name=test-library
ng generate service service-name --project-name=test-library

Declare Repository Homepage Keywords License on NPM (package.json)

2021 Library Angular 2+
{
  "name""ngx-shift-jis",
  "version""1.0.3",
  "description""This library is built for the purpose of loading files in 'shift jis' format.",
  "keywords": [
    "ngx",
    "angular2",
    "shift-jis",
    "ngx-shift-jis",
    "encoding-japanese"
  ],
  "author""DaiDH <duonghuudai.id002@gmail.com>",
  "license""MIT",
  "repository": {
    "type""git",
    "url""git+ssh://git@github.com/id1945/ngx-shift-jis.git"
  },
  "peerDependencies": {
    "@angular/common""^12.0.5",
    "@angular/core""^12.0.5"
  },
  "dependencies": {
    "encoding-japanese""^1.0.30",
    "tslib""^2.1.0"
  },
  "devDependencies": {
    "@types/encoding-japanese""^1.0.18"
  }
}

Add External Js File In Angular Library (Angular)
2021 Library Angular 2+
npm install encoding-japanese --save
npm install @types/encoding-japanese --save-dev
Then: import * as encoding from 'encoding-japanese'; Refer Required: Refer "allowedNonPeerDependencies" Angular version 12 "whitelistedNonPeerDependencies": Angular version 8

Library Test On Local Environment
2018 Library Angular 2+
cd dist/my-lib
npm pack

ng new
demo npm i "this path" --save

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang