I've found a lot of blog posts that seem to suggest publishing a library TypeScript (as source) and all to npm or to a private repository. It feels like we should be doing some transpiling first and then publishing only something that is ready to consume.
Can you critique my approach for publishing a angular-cli+angular(4) components library to npm or like?
Context
Multiple angular front-end SPA's that may have common components i.e. a navigation bar. These common components could be published as a library including the navigation bar to npm or a privately scoped npm repository for use by the various front-end apps.
The common components could be developed in a project using angular-cli, angular(4).
Approach
- Create
tsconfig.aot.jsonwhich inherits fromtsconfig.jsonso that we can aot transpile the project back toes5- Ensure that metadata and index files are included/emitted
- Ensure the
src/.npmignorefiles are in place to include/exclude files already excluded by the.gitignore
- When the tests pass with
ng test,ng e2e,ng lint, andng buildas described in the.travis.ymlnpm version patch(ormajoretc.)git push+git push --tags
- When the tag passes on CI
ngc -p tsconfig.aot.jsonwhich will create the distributionnpm publish
Code
The code can be found on GitHub
Referenced files
tsconfig.aot.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "",
"module": "es2015",
"baseUrl": "",
"types": [],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
},
"files": [
"src/app/app.module.ts",
"src/main-aot.ts",
"index.ts"
],
"angularCompilerOptions": {
"genDir": "./dist/aot",
"skipMetadataEmit" : false
}
}
tsconfig.aot.json
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": true,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"./node_modules/@types"
],
"lib": [
"es2016",
"dom"
]
}
}
src/.npmignore
*.ts
!*.d.ts
.npmignore
.travis.yml
language: node_js
dist: trusty
node_js:
- 6.1
sudo: required
addons:
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
- google-chrome-beta
before_install:
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
install:
- npm install
- npm install codecov
script:
- npm run ng test -- --single-run=true --browsers Chrome --code-coverage
- ./node_modules/codecov/bin/codecov
- npm run ng e2e
- npm run ng lint
- npm run ng build
- npm run package