wanderyt的博客

会踢足球的程序猿


  • 首页

  • 归档

  • 标签

  • 搜索

npm vs bower vs grunt vs gulp

发表于 2015-07-24 | 分类于 Nodejs

npm vs bower

首先,两者都是包管理工具。主要的区别在于:

npm是用于管理node的js包,而bower更偏向于管理前端组件,比如html,css,js等等

实际上,npm也提供一些前端开发的包,比如grunt,jshint。不过个人认为这些也还算是node的后端开发工具。

以下这段可能更加说明区别。

Bower, unlike npm, can have multiple files (e.g. .js, .css, .html, .png, .ttf) which are considered the main file(s). Bower semantically considers these main files, when packaged together, a component.

bower,不像npm,可以包含多种多样的主要文件(.js, .css, .html, .png, .ttf等等)。这些文件都会被认为包的主要文件。bower在提交类库时,这些文件都会被一起打包。

Grunt

Grunt与npm和bower完全不同,Grunt是一个javascript的任务工具,利用grunt,我们可以做很多其他时候必须人工维护的事情。点出几个Grunt的几个重要用途。

Zipping some files (e.g. zipup plugin)

Linting on js files (jshint)

Compiling less files (grunt-contrib-less)


npm与bower最大的区别在于,npm主要运用于Node.js项目的内部依赖包管理,安装的模块位于项目根目录下的node_modules文件夹内。而Bower大部分情况下用于前端开发,对于CSS/JS/模板等内容进行依赖管理,依赖的下载目录结构可以自定义。

有人可能会问,为何不用npm一个工具对前后端进行统一的依赖管理呢? 实际上,因为npm设计之初就采用了的是嵌套的依赖关系树,这种方式显然对前端不友好;而Bower则采用扁平的依赖关系管理方式,使用上更符合前端开发的使用习惯。

不过,现在越来越多出名的js依赖包可以跨前后端共同使用,所以bower和npm上面有不少可以通用的内容。实际项目中,我们可以采用NPM作用于后端;bower作用于前端的组合使用模式。让前后端公用开发语言的同时,不同端的开发工程师能够更好地利用手上的工具提升开发效率。


gulp vs grunt

Gulp官网

Grunt利用一些内嵌的功能来完成一些基本的用途。Grunt是基于配置来完成功能的。

Gulp不是立即可用的,它是基于插件流来完成一个复杂的工作流。

这两种工具都可以将多个任务并行执行,但Gulp会尝试同时执行尽可能多的任务,同时保证任务之间的依赖关系。

Gulp常用的方法有四个:

gulp.task();    // 定义任务
gulp.watch();   // 监测文件系统的修改
gulp.src();     // 打开文件/文件夹
gulp.dest();    // 输出文件/文件夹

常用的gulp插件有:

gulp-ruby-sass : 支持sass 
gulp-minify-css : 压缩css 
gulp-jshint : 检查js 
gulp-uglify : 压缩js 
gulp-concat : 合并文件 
gulp-rename : 重命名文件 
gulp-htmlmin : 压缩html 
gulp-clean : 清空文件夹

Chrome跨域访问

发表于 2015-07-24 | 分类于 UI Development

Chrome跨域访问

在chrome快捷方式,目标里如下设置

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security

11段有用的Javascript代码

发表于 2015-07-23 | 分类于 UI Development

来源:11 JavaScript Code Snippets for Dynamic Web Projects

11段在Web开发中有用的代码。

开一个新的窗口

window.open("http://webdesignledger.com","newWindow");

探测浏览器的关闭

一般用户在点击浏览器右上方的关闭按钮时,你可能希望提示用户一些信息。当然,一些比较讨厌的网站会使用这项功能来满足他们的市场需求,比如弹出一个广告或者警告框来保证用户能在他们的页面上多停留片刻。

function checkBrowser() {
    // triggers on clicking the close button, Alt+F4 , File->Close  
    if(window.event.clientX < 0 && window.event.clientY < 0) {
        window.open("somefile.html", "closewindow",'left=12000,top=1200,width=120,height=50');
    }
}

这样确实不值得推荐。

不过,更多的时候你可以很好的利用这个功能。比如,可以在用户关闭浏览器之前清理用户的Cookies会话信息。这是处于你自己网站的安全考虑,阻止其他人使用不同人的账户来错误的获取网站数据。

阅读全文 »

npm基本指令

发表于 2015-07-23 | 分类于 Nodejs

npm的详细讲解在npm官网上的documentation中已经说的很全面了,我只是想简单的提取出其中的一些比较重要的部分。

权限问题

$ npm config get prefix         // 获取npm根路径
$ ls -l                         // 查看文件权限
$ whoami                        // 查看当前用户
$ sudo chown your_user filename // 改变文件权限

项目内安装npm包

$ npm install lodash

直接在当前路径下安装node module

$ npm install

此方法会直接读取当前路径下的package.json文件,并根据其中的dependency,自动安装node module

$ npm install lodash --save

自动将lodash的安装信息添加到对应的package.json文件中

"dependencies": {
    "lodash": "^2.4.1",
    "tap": "*"                  // 自动获取最新版本
}

更新项目内npm包

$ npm outdated                  // 查看已过期的npm包版本信息
$ npm update                    // 更新所有npm包

卸载项目内npm包

$ npm ls                        // 查看所有项目内的npm包
$ npm uninstall lodash          // 卸载lodash包,但package.json中不会删掉对应的dependency
$ npm uninstall lodash --save   // 卸载lodash包,dependency也会删除

$ npm prune                     // 根据dependency,删除node_module中未定义关联的npm包

全局安装npm包

$ npm install jshint -g         // 安装jshint
$ npm config get prefix

全局更新npm包

$ npm outdated -g [--depth=0]   // 查看过期的全局npm包,--depth控制文件深度
$ npm install -g

卸载全局npm包

$ npm uninstall -g jshint

Angular Route Analysis

发表于 2015-07-21 | 分类于 AngularJS

之前去面试前端工程师的时候,提到AngularJS总会被问到一个问题,AngularJS的路由的实现原理是什么。

自己的理解一直不是很深,看过的技术帖子也没有讲的比较深入的,今天总算看到一篇细致的讲解。分享一下。

转自: Angular路由深入浅出

阅读全文 »

Bootstrap vs Material Design Lite

发表于 2015-07-21 | 分类于 UI Framework

Source : Comparing Bootstrap With Google’s New Material Design Lite

Key Differences

Before we dive into the examples, let’s brake down the major differences between Bootstrap and Material Design Lite:

Philosophy

Bootstrap was originally built by Twitter with the purpose of making it easy to build responsive websites. It gives you a lot of components and customization options for making web apps.

Material Design Lite is a way for Google to spread its material design concept to the web. It gives you only the base building blocks for building material apps. The rest is up to the developer.

Development Experience

Bootstrap has a very detailed documentation. Development involves copy pasting from the examples and getting a usable result fast.

MDL is built around BEM, and components are built by combining multiple classes. This approach gives a great deal of control, but can sometimes lead to unwieldy HTML.

Components

In Bootstrap, almost all built-in HTML elements are styled and can fit nicely together in a layout. It gives you a great number of additional components for any type of design.

MDL gives you fewer components than Bootstrap, but they are all focused on building modern Material Design applications. They come with animations and beautiful default styles.

Layout

Bootstrap has an advanced grid system with offsets, column wrapping, hiding and reordering of columns.

MDL has a more primitive grid that gets the job done most of the time, but doesn’t support advanced features.

Design

Bootstrap gives you a passable default design which we have grown tired of by now, but there are plenty of wonderful themes to chose from.

MDL looks fresh and features bold colors and animations. It dictates exactly how your web app should look like and gives you a limited opportunity for customization by choosing base and accent colors.

Community

Bootstrap has been around for quite some time and has an enormous community, which produces themes, plugins and blog posts.

MDL came out only recently but has already become quite popular on GitHub. However it is still in its early days, and most of the time you are on your own.

But how do these frameworks compare in practice? This is a more difficult question to answer. This is why we’ve prepared a number of examples implemented in both frameworks that will help you compare what they are capable of. Click the images to see the examples side by side.

Here is the comparison view for each main category.

Demo Kit : http://demo.tutorialzine.com/2015/07/comparing-bootstrap-with-mdl/?grid

阅读全文 »

Error in initializing Git Extension

发表于 2015-07-15 | 分类于 Git

Problem

When initialize git extensions, an exception thrown by the type initializer for GitCommands.AppSettings

Popup window says:

System.Xml.XmlException

Exception Details:

System.TypeInitializationException: An exception was thrown by the type initializer for GitCommands.AppSettings —> System.Xml.XmlException: Unexpected XML declaration. The XML declaration must be the first node in the document, and no white space characters are allowed to appear before it. Line 104, position 9.

Solution

The problem was in the file
/home/user/.local/share/GitExtensions/GitExtensions.exe_Url_fc9221118986807f24034ab13ad4e7143ae90814/user.config

Contain malformed XML.

Remove the file, and problem gone.

Why? No reason found on web. Waiting to see further details.

Source: https://github.com/gitextensions/gitextensions/issues/2710

分离Github代码和博客生成代码

发表于 2015-07-13 | 分类于 Blog stuff

1. 问题

玩Hexo两天了,发现一个很重要的问题。

利用hexo命令创建博客的markdown文件,之后用deploy命令来生成博客页面并发布到github上。

git bash中输入这两行命令

$ hexo deploy
$ git fetch

很平常的举动,我要fetch一下远程代码,然后要把本地的修改提交。怎么一下子那么多冲突?OMG

这个问题网上居然没有多少帖子讨论,只能自己开工搞一搞了。

想起来一个兄弟在自己的技术博客里写过一句话:程序猿就要是多搞搞才行。

其实,是由于在 _config.yml 文件中设置的

# Deployment
## Docs: http://hexo.io/docs/deployment.html
deploy:
  type: git
  repository: http://github.com/wanderyt/wanderyt.github.io.git
  branch: master

导致的。

我没有查到这个branch的作用,但是经过测试,这里的branch应该是指博客页面通过读取repository中远程master上的代码来生成的。

好了,现在就出现问题了,我们当前默认的工作目录所在的branch也是master。所以当我们push本地代码到远程master分支时,就会提示冲突之类的错误了。

阅读全文 »

Hexo中添加主题等其他功能

发表于 2015-07-13 | 分类于 Blog stuff

这一篇主要做一些Hexo的后续工作。

1. 主题

1.1 安装主题

Hexo的主题列表

下载主题

$ git clone <repository> themes/<theme-name>

比如,我用的是next主题,命令行输入

$ git clone https://github.com/iissnan/hexo-theme-next themes/next

1.2 配置主题

全局配置文件 _config.yml 中 theme 一行改成想要的主题。

theme: next
阅读全文 »

用Hexo搭建Github博客

发表于 2015-07-13 | 分类于 Blog stuff

1. 安装node.js

Node.js官方下载: Node.js

2. 配置Github

2.1 建立Repository

建立与你用户名对应的仓库,仓库名必须为: your_user_name.github.io

2.2 配置SSH-Key

3. 安装Hexo

3.1 Git Command

打开Git Bash,执行如下命令

$ npm install -g hexo
阅读全文 »
1…45
wanderyt

wanderyt

wanderyt Blog

50 日志
12 分类
27 标签
RSS
github weibo twitter
© 2015 - 2019 wanderyt
由 Hexo 强力驱动
主题 - NexT.Muse