Publish angular2 module / component as npm package

I would like to create my library in npm from Angular2 components (my common grid, my common buttons, etc.) and modules (my clients are in a modular module), but I cannot find any working example on the Internet (I found somewhat, though, but it never works ...

index.js:

export { PortalGridComponent } from './src/portal-grid/portal-grid.component';

Here is my package.config.json:

{
  "name": "my-perso-components",
  "version": "1.0.13",
  "main": "index.js",
  "scripts": {
    "nbuild": "tsc index.ts --outDir ./lib",
    "build": "tsc -p src/",
    "build:watch": "tsc -p src/ -w",
    "build:e2e": "tsc -p e2e/",
    "serve": "lite-server -c=bs-config.json",
    "serve:e2e": "lite-server -c=bs-config.e2e.json",
    "prestart": "npm run build",
    "start": "concurrently \"npm run build:watch\" \"npm run serve\"",
    "pree2e": "npm run build:e2e",
    "e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first",
    "preprotractor": "webdriver-manager update",
    "protractor": "protractor protractor.config.js",
    "pretest": "npm run build",
    "test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
    "pretest:once": "npm run build",
    "test:once": "karma start karma.conf.js --single-run",
    "lint": "tslint ./src/**/*.ts -t verbose"
  },
  "dependencies": {
    "@angular/common": "~2.4.0",
    "@angular/compiler": "~2.4.0",
    "@angular/core": "~2.4.0",
    "@angular/forms": "~2.4.0",
    "@angular/http": "~2.4.0",
    "@angular/platform-browser": "~2.4.0",
    "@angular/platform-browser-dynamic": "~2.4.0",
    "@angular/router": "~3.4.0",
    "angular-in-memory-web-api": "~0.2.4",
    "systemjs": "0.19.40",
    "core-js": "^2.4.1",
    "rxjs": "5.0.1",
    "zone.js": "^0.7.4"
  },
  "devDependencies": {
    "@types/core-js": "^0.9.35",
    "@types/jasmine": "^2.5.36",
    "@types/node": "^6.0.46",
    "canonical-path": "0.0.2",
    "concurrently": "^3.1.0",
    "jasmine-core": "~2.4.1",
    "karma": "^1.3.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "lite-server": "^2.2.2",
    "lodash": "^4.16.4",
    "protractor": "~4.0.14",
    "rimraf": "^2.5.4",
    "tslint": "^3.15.1",
    "typescript": "~2.0.10"
  },
  "license": "ISC"
}

my tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [ "es2015", "dom" ],
    "noImplicitAny": true,
    "outDir": "./lib",
    "suppressImplicitAnyIndexErrors": true,
    "typeRoots": [
      "./node_modules/@types"
    ],
    "types": [
      "core-js"
    ]
  }
}
  • and my project architecture is as follows:

     - lib
     - node_modules
     - src
         - app
         - my-perso-grid
            - my-perso-grid.component.ts
            - my-perso-grid.html
            - my-perso-grid.scss
     - .npmignore
     - index.ts
     - package.json
     - tsconfig.json
    

Then I run tsc index.ts --outDir ./liband make the npm version of patch, then npm publish.

My code is in npm for sure, I can install it in another folder ... However, I always get 404 problem:

Error: (SystemJS) XHR error (404 Not found) loading http: // localhost: 3000 / my-perso-components Error: XHR error (404 not found)

, , !

? ? , npm?

... .

+4

Source: https://habr.com/ru/post/1669093/


All Articles