Automatically add js/css files to ionic projects - angularjs

I want to automate the injection of new js/css files to my ionic project. So, I found this really useful article, which shows how to do it using gulp inject, but just with my own js/css files (those in js/css folders).
If I now install another external library using bower, for example:
bower install angular-google-maps --save
That library is not automatically injected, because it's installed in lib folder, outside js folder, as it's a library from an external vendor.
I guess I should have another gulp task to minimize the external libraries installed with bower, and put them into js folder to make them injectable. Am I right?

Yes, you are right.
Quoting your article:
There is all of kinds of additional functionality that you can perform with gulp such as minifying of css and javascript files, running npm/bower commands, or running sass compile commands. The gulp-inject is just one module.
You can use a module like main-bower-files to retrieve these files and do whatever you want with them.
You can also have a look at this answer to get a starting point.

Related

Angular2 with maven project

I have a question, I want to use angular 2 in maven project, and as you now the modules should download with ( npm install or ng new .. (cli) ).
The problem is if I generate the war file with all this modules, it will be very large because of the presence of all the nodejs modules.
In one of Github example they install this modules with ( npm install ) and finally goes to the home directory and run spring-boot:run
I want directly deploy my war file, so my question is : i should generate the war file with the all the modules and dependencies of nodejs or there is another solution ?
Three ways:
add all node_modules dependencies in to your version control, so source is always there, or copy necessary js libraries manually in specific source folder, like angular.min.js and so on (if your node.js is not available on your server, by security reason)
create execution goal inside pom.xml, something like
How to deploy a node.js app with maven?
use https://github.com/eirslett/frontend-maven-plugin and check existing examples, I am sure your case is straight forward

How to deploy the integrated 3rd party directives in Angularjs project

Say, I need to use Wysiwyg editor and I found a 3rd party directive for it.
It has a good readme and how to setup in my project(Local).
Demo link: Wysiwyg Editor
Considering that I have done all the npms and integrations in my local project.
How can I deploy the project with new changes?
Maybe I am asking because I don't know about gulp or bower. Does my project needs to have gulp ad bower in order to use such directives. If so, how will the deployment go post setup and integration.
Assumption : There are no gulpfile.js and bower setup already.
In Jquery using a plugin is quite simple. Add a script tag for js file of plugin and use it in html or js as instructed. Does the process has to complicated always for using a 3rd party angular directive?
No. It is not compulsory to use gulp. Gulp just runs task like adding css,js to your file , minifing it and like.
you need to add js file which contain directive code. In your case it is
this is your link of directive
Now you can save this data in one of your js file and add it in index.html
OR
you can give this online link.
Using external directive need to add js n css file.
Question is will it work? We have to see dependancies of any external module we are using so what are dependancies of this module?
enter link description here
you need to add this module also
ADVANTAGES:
Using bower: you can install module in your project. bower install will download all your dependancies also.
using gulp : Gulp task will make sure of adding your css and js files in index.html

MEAN.js - Should all js files be merged when deployed

I have a problem with a MEAN.js app in that its really slow to load and from the inspect i can see that its loading js in 70 different files.
Couple of questions
Why is there so many js files seperate? Can they not be merged into one and served quicker like YSlow advises?
Edit
'modules/*/client/*.js',
'modules/*/client/**/*.js'
Folder Structure
modules/savings/client/controllers/client.controller.js
MEAN.js has that particular aspect covered. In fact, if you run your app using just grunt command, the app will start running in development environment, and so the js files (either the ones from 3rd party libraries or even your custom js files) are not concatenated nor minified. This helps you while debugging. However this is clearly not good for an app in production in terms of performance.
If you use the command grunt prod your app will start running in production mode and so your custom js files will be concatenated and mninified. 3rd party library files won't be concatenated but grunt will use the minified version of them.
You can see which assets will be loaded for both development and production modes in config/assets/development.js and config/assets/production.js, respectively.
Also if you want to see what are the differences between both grunt and grunt prod tasks you can check your gruntfile.js.
Note 1: The commands I mentioned about grunt can also be used with gulp, since MEAN.js has both a gruntfile.js and a gulpfile.js defined.
Note 2: If, by the time you use grunt prod and still have so many files being loaded, that means you are using an high number of 3rd party libraries and a possible solution for that case is to concatenate 3rd party library files into a vendor.js file however in doing that you might run into trouble, such as some libraries like AngularJS needing the files to be loaded with a specific order. You will need extra caution if you edit your gruntfile to implement such task.

How to reference package added by Bower?

In VS.NET 2015, I've added a reference in bower.json for angularjs. This caused the angularjs package to be downloaded, which I can see in the Bower folder.
However, I'm not able to execute any angularjs code. I do have an ng-app in the HTML tag. If I add a CDN reference to the angularjs library, it works fine.
What am I missing to use the package downloaded by Bower?
what are you missing is referencing the downloaded libraries in bower_components folder in your index.html.
For example let's say you added restangular to bower. the library while reside in ./bower_components/restangular so in your index.html ( your SPA). you will reference it like this :
<script src="../bower_components/restangular/dist/restangular.js"></script>
Beware sometimes you should add all the library main files ( js and css), for that you need to check the value of the main attribute included in the bower.json of the library . for our example in bower.json in ../bower_components/restangular/ we have:
"main": "./dist/restangular.js",
In a the file .bowerrc you may define the directory for the downaloaded libraries in my example it will be bower_components.
In your .csproj file add the
<Content Include="bower_components/restangular/dist/restangular.js" />
Use can see this example
Since more than likely for production deployment you won't be deploying things in bower_components directory, I suggest you setup a gulp or grunt task to copy all the JavaScript that you are going to use and probably minify and concat / bundle them into a folder in wwwroot like /lib or /js or whatever your convention is going to be and add a script tag pointing to that bundled version. There is a decent walkthrough by Mads Kristensen from the recent Build event that you might want to look at. He demoed all the things you would probably need to get your app running.

Adding packages like moment.js & account.js to meteor Project

How do I add these JS packages to a meteor project? Do I simply place the JS files in the public folder so the client and server can access them? Or is there some specific steps that I need to follow?
These kind of standalone libraries can be directly placed in the /lib directory under your project.
For use on both the client and the server, place them into project/lib folder.
Or if you want to use them only at client-side, place them as usual in project/client/lib
In short, It depends.
I would recommend you check out http://atmosphere.meteor.com for a list of packages. If what you're looking for is there, install meteorite with npm install -g meteorite (https://github.com/oortcloud/meteorite)
Once you have metorite installed you can install these community packages quite easily using mrt add packagename
Most packages are on http://atmosphere.meteor.com.
But if for some reason the JS package you want isn't on atmosphere, depending on the package, if its a UI package (e.g datepicker, etc) put it in the /client/lib folder to avoid meteor crashing (only accessible by client).
If its a type of module abstractor (e.g backbone - backbone is included in meteor already btw: add using meteor add backbone) you could put it in the /lib directory of your package, it will be referenced automatically by both the server and client.
You have to add the packages via console.
Type "meteor add accounts-password" for example.
See here
Perhaps you should watch some of these videos here
to get an idea how meteor packages are added.

Resources