packages (optional): make sure you use a version of TypeScript compatible with Angular Compiler
and run npm install.
Create your classes in src folder, and export public classes in my-library.ts.
You can create only one module for the whole library:
I suggest you create different modules for different functions,
so that the host app can only import the modules it uses, and optimize its Tree shaking.
Update in rollup.config.js file globals external dependencies with those that actually you use to build the umd bundle.
Create unit & integration tests in tests folder, or unit tests next to the things they test in src folder, always using .spec.ts extension.
3 Testing
The following command runs unit & integration tests that are in the tests folder (you can change the folder in spec.bundle.js file):
npm test
or in watch mode:
npm run test:watch
It also reports coverage using Istanbul.
4 Building
The following command:
npm run build
starts TSLint with Codelyzer using Angular TSLint Preset
starts AoT compilation using ngc compiler
creates dist folder with all the files of distribution, following Angular Package Format (APF):
"strictMetadataEmit": true without emitting metadata files, the library will not be compatible with AoT compilation: it is intended to report syntax errors immediately rather than produce a .metadata.json file with errors
"flatModuleId": "@scope/package" full package name has to include scope as well, otherwise AOT compilation will fail in the consumed application
"enableIvy": false libraries don't need to enable Ivy
rollup.config.js file used by Rollup
format: 'umd' the Universal Module Definition pattern is used by Angular for its bundles
moduleName: 'ng.angularLibraryStarter' defines the global namespace used by JavaScript apps
external & globals declare the external packages
Server Side Rendering
If you want the library will be compatible with Server Side Rendering:
window, document, navigator and other browser types do not exist on the server
don't manipulate the nativeElement directly
9 Inlining of templates and stylesheets
Now ngc compiler supports inlining of templates & styles. Moreover, this starter allows you to use .scsssass files. If you need, you can use different pre-processors.
ngx-storeAngular Storage library for managing localStorage, sessionStorage and cookies, allowing to watch storage changes. Includes easy-to-use decorators, services and API based on builder pattern.
ngx-table-editorA library for Angular that transforms HTML tables into dynamic editable components.
ngx-ui-scrollAn Angular *ngFor-like directive for infinite/virtual scrolling
请发表评论