angular2-library | How to create a library in Angular2 | Build Tool library
kandi X-RAY | angular2-library Summary
kandi X-RAY | angular2-library Summary
this project show how to package a library using ngc. For more information please visit: ###how to install npm install. ###how to package the library npm run build. ###how to use the package in your project npm install ../angular2-library (specify the correct path).
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of angular2-library
angular2-library Key Features
angular2-library Examples and Code Snippets
Community Discussions
Trending Discussions on angular2-library
QUESTION
Hi I am trying to build a custom Angular Library. Using yeoman-generator (link) I get a template to build upon, that works just fine. The problem is that it uses a (not anymore best practice) barrel index.ts
, and what I want is to be able to have one module per component and import accordingly.
ANSWER
Answered 2017-Sep-07 at 05:28In case someone faces the same problem, here is how my files are now structured and connected:
I have a component with the desired functionality HelloWorld
Then a module for this component:
QUESTION
I'm building an Angular (2+) component library using jvandemo/generator-angular2-library as a starter, which uses Rollup as a module builder. The component I am creating in the library uses MomentJS.
I've had various build issues with the inclusion of MomentJS.
I first used import moment from 'moment';
to import moment into the component, but that produces the following error at build;
ANSWER
Answered 2017-Oct-25 at 21:59In the sample directive I had no problem compiling when I used the following:
QUESTION
I recently upgraded an existing Angular 6 App to Angular 7. Most of my App was built on Angular 6 and then I upgraded it.
Here's my package.json:
...ANSWER
Answered 2018-Oct-30 at 06:40I had the same WARNINGS and ERROR after upgrade from Angular 6 to Angular 7. I have deleted my node_modules folder then npm install again. Now the compilation succeeds without warnings and I have no more the error "Uncaught TypeError: e is not a constructor".
QUESTION
I'm following the Angular CLI 6 instructions for creating a library here. I was able to make my library, and build it successfully. The library consists of a Component
I am using for the UI and has an HTML selector
.
ANSWER
Answered 2018-Jun-08 at 03:26Only issue i see is that your instance of the service also has the same name, change it as
QUESTION
Hi guys I need a bit of help, as I can't seem to get it to work. I think I might be using the incorrect syntax or something.
I am currently building Angular 4 libraries using YO https://github.com/jvandemo/generator-angular2-library
So everything is working except for the @Input
decorators.
Some simple code here
...ANSWER
Answered 2018-Mar-07 at 09:10Here is your mistake:
QUESTION
I generate my angular 2 lib with yeoman generator and added to main angular project. If i compile app in dev mode i haven't error, but if i run prod mode, i get many errors:
...ANSWER
Answered 2017-Nov-16 at 20:51Your intent was probably to export just what is needed, but you need to export everything from your src/index.ts
file, including all the services, directives, and pipes.
QUESTION
I am currently building an Angular library, and I wanted to be able to run some tests. After following these instructions I managed to set up everything properly and actually be able to run my tests.
Main question
Although everything runs properly something awkward happens. When I run npm test
next to every .ts
file a .js
file is generated. Normally all the d.ts
and the one big .js
files go inside a dist
folder that projects using the library use. So does anyone know from where could these javascript files are generated, and if they are indeed needed, since all this code already exists so to speak in the dist folder.
Bonus question
Not as important as the above, all the test results are displayed in the terminal, whereas the browser displays only:
Karma v1.4.1 - connected Chrome 61.0.3163 (Mac OS X 10.12.6) is idle
So is there a nice fix to display my test as nicely as the angular-cli
does out of the box?
Note that after doing my homework I did not find something relative online, and I don't want to upload a bunch of unpleasant jsons. If anyone has an idea on the direction of the problem I will be happy to include code.
The basic structure of my library was generated by this
Edit:
karma.config.js
ANSWER
Answered 2017-Oct-18 at 16:06You are getting .js
file for every .ts file because of your typescript configuration. You can change your configuration in tsconfig.json
to tell compiler that write a single file or in a folder and add all script there.
"outDir": "../out-tsc/spec"
--> will add all output javascript files in a single folder.
For your second question, When karma runs internally it runs webdriver
and connect to the browser. That is the reason you see localhost:9876
or similar url open with a debug button at the right.
While the webdriver is running you can also debug any bug situation in the browser and lot more.
QUESTION
I red this article about creating Angular 2 component library, and it uses inline styles. Is there a way to create a lib without inline styles in Angular 2?
Also I saw this, but there is no word about styles, css.
My problem is, I want to create a complex component with multiple components in it and I use SASS also.
...ANSWER
Answered 2017-Sep-22 at 03:57The problem here is that when you compile your npm package the styles templates must be inline because when you load it as a npm package you won't be able to achieve the template/css path inside node_modules.
The Angular Material 2 team used the follow gulp task to inline the css and template in its components:
They have created this task file that
- Get external CSS and put inline;
- Get external Html and put inline;
- Removes the module.id from components;
Finally, in the build process they call this task here.
My approach of doing this:Install
gulp
,gulp-angular-embed-templates
,gulp-inline-ng2-styles
.Create a file called
gulpfile.js
at the root of your appadd the following code to your
gulpfile
:
QUESTION
I am trying to create an Angular 2 library for services, components, and models I want to share between 3-4 different interfaces/apps that are frontends to the same database.
I am using the very helpful Angular 2 generator library here.
My services in the library are based around Apollo client and GraphQL.
However, when I symlink the library build to import into my main project, the Apollo dependencies don't seem to resolve.
I get the following two errors from my app build: Can't resolve 'apollo-angular/index'
and Can't resolve 'graphql-tag/index'
. This is in spite of the fact that both these libraries are installed to my node_modules
in my app, however, they don't seem to transferred by the Gulp build into my dist
directory of my library but I am not even sure they are meant to be.
I have also tried to setup peer dependencies in my library's package.json
as follows:
ANSWER
Answered 2017-Jul-27 at 16:03It might occur because of this issue.
Try to define paths in your ts
QUESTION
I have created an angular componet (datetime-popup) found here
I want to be able to use it in my projects, but i cannot get it to work. I believe i need to make it a umd library or something with webpack, but i have had a look on this internet and i cannot find how to do this, as whatever i do, it errors.
Can someone help me to sort this out? I would like to be able to reference the project in the demo, and also use it via an external project using npm.
EDIT:
I have tried to duplicate this project but for some reason, when i build my example project, it get an exception in a script
bundle.js:39725 Uncaught SyntaxError: Unexpected token export
Here is the exception. This isnt my code and works fine when the ngx-bootstrap project is in the project
...ANSWER
Answered 2017-Jul-18 at 11:56Packaging Angular libraries is still a bit of a black art. It is on the angular-cli roadmap to provide better out-of-the-box support. Meanwhile, you can consult this excellent overview.
Basically, you need to compile your modules and components with ngc
, based on a tsconfig.json
with specific settings, this being a necessary step in order to create the metadata required by Angular builds, and in-line the templates and CSS (pre-processed if necessary) if they are in external files. The consuming application then imports the modules and components from the directory into which they have been compiled, often something like dist
or lib
, which can be accomplished with an entry in package.json
such as "module": "dist/index.js"
. If you are publishing to npm
, then you could simply publish the dist
directory. It is beyond the scope of this short answer to provide more exhaustive details.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install angular2-library
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page