Can/should Grunt be used with Bower without Npm? - gruntjs

I am a little confused about the use of Npm, Bower and Grunt. My objective is to install frontend packages (e.g.: bootstrap) for my front-end project and have Grunt set up to automate build tasks.
I have been using Npm in the past and I understand that it works with the package.json file, while Bower works uses the bower.json file. In this case, I installed Grunt with Bower (not Npm), however I realised that in order to run Grunt I still need to add the package.json file.
Should I have been using Bower to install Grunt at the first place ?
Does my project always need the package.json file to use Grunt? And
if so, are there any good practices for dealing with the duplication
between the bower.json and package.json files. (name, version of the app, etc…)
Thanks

grunt (grunt-cli) is command line task runner, not frontend library :), so installing it via bower is strange, but possible due to the fact that bower is using npm as base repository :)
package.json store all tool dependencies in your project - like bower or grunt
In frontend development bower should be handling css/js libraries in your app like jQuery, Angular.js, Bootstrap. NPM is for node.js extensions/utilities like grunt, karma devDependencies.
http://blog.nodejitsu.com/package-dependencies-done-right/

Related

Is there a way to install animate.css via Bower/Homebrew/etc?

I've finally started developing locally and have installed Roots.io for WP builds. Bower, gulp, node, it's all great. I've used Bower to install wow.js and it's there, but the dependency is animate.css. Is there a way to install animate.css via Bower/Homebrew/etc?
On the animate.css Github I don't see a simple way to include it in the Roots build. I've tried to manually include in which hasn't worked either, hence looking for the ideal/clean solution to the problem.
Thank you!
When installing dependancies via bower (or any package manager really) that project should include a manifest (bower.json) that lists it's own dependancies. E.g. The bower.json in wow.js should include a reference to animate.css. However if it does not you can include it as any other dependancy:
bower install animate-css --save
Then run you build process again. In this case:
gulp

Use gulp locally outside node

I would like to use gulp in my Wordpress project. Is it possible to execute gulp functions outside a node JS project?
I'm running on OSx, but couldn't find anything on the internet about it. Or do I'll have to use another lib like Grunt?
Yes, the main language of your project doesn't affect whether or not your can include some node.js dependencies and run them. You will need to have gulp installed and have a gulpfile.js in your project, and then you can run it.
You could install gulp globally on the server (npm install -g gulp), but I recommend creating a package.json file (using npm init) in your project, so that your node.js dependencies are tracked in your version control, and installing gulp with npm install --save gulp (inside your project's directory). Since gulp won't be installed globally in that case, you will need to use "$(npm bin)"/gulp from a directory inside your project to run it.
I use Yeti Launch from the Zurb foundation for the same setup (no node installed on my Mac).
When you run it, it will create a Foundation frame but you can do the following:
Stop the project it creates from within its interface,
Delete the files it creates and replace with yours
Leave the project it shows in the interface
Leave the "node_modules" folder it creates
Start the project again
This will run your Gulp file.
The only issue is installing node modules. For this, I look at any error messages it gives regarding missing modules and copy these into the "node_modules" folder from Github
The short answer is no. Gulp is distributed as a npm package and has node.js as a dependency BUT that doesn't mean you can't use it outside of a node.js project.
The only real need for Gulp on a wordpress project would likely either be at the theming layer or if you were doing a custom plugin. Assuming you are making a theme, some of them use Gulp extensively.
I've used the Roots ecosystem's Sage theme successfully on a number of projects. It has node/npm dependencies but they are all included if you use the theme. Check out their Gulp file - it's probably close to what you are philosophically looking for.

What is the correct option to use Grunt locally and on the production server, --save or --save-dev?

The install page on the Grunt website gives the following suggestion
Grunt and Grunt plugins should be defined as devDependencies in your
project's package.json. This will allow you to install all of your
project's dependencies with a single command: npm install.
I want to use grunt to run some tasks that are specific to local development, e.g.
development: concatenate javascript, but dont minify
production: concatenate and minify javascript
If I install Grunt as a dev dependency, does this mean when I run NPM install on the production server - grunt will not be installed into node modules?
What is the correct option to be able to use Grunt both locally and on the production server?
It doesn't matter if you install Grunt as a dev dependency, it will still be installed when you run npm install.
The scenario where dev dependencies are not installed is when you run npm install <package> because the consensus is you are an end user looking to use (not build/test) the package. However, you can still include the dev dependencies by adding the --dev flag.
You should install grunt with --save-dev. What it does is add a line to your project's package.json. Similar to when you install any other node module with --save-dev. Then, if you run npm install on any machine with the same package.json, all those modules will be downloaded and installed locally, and usable by your project.
As for running different tasks in production and development, I assume you know how to configure grunt to do that.

bower dependencies to CONCAT to a project

I have a project and the current bower dependencies are a good fit for me.
is there a way to concat them to the project without each time call bower install?
To concat assets you should look at grunt-contrib-concat. This will allow you to concatenate all your files.
In terms of the bower install you shouldn't have to run that each time, only when there is a fresh install of the project and the dependencies need to be added.
Bower install will install the dependencies needed and bower update will update dependencies based on what is specified in the bower.json.

Questions about install gruntjs

Im trying to start using gruntjs. But the official documentation is confusing me.
Should I write package.json file myself or any command would create it for me?
Uglify, concat, jshint all those plugins they used in the sample gruntfile, are they installed as grunt is installed?
When a plugin is installed, is it installed globally or I should install it everytime I create a new project?
You can write it yourself or create it with npm init or grunt-init.
No, you add the plugins you want to the package.json as devDependencies, then npm install to install them.
Plugins are project specific and are installed locally to your project.

Resources