Cordova, Grunt and Coffee

You may reference to below if you deside to work with coffee instead of Javascript in Cordova project.

Prepare Cordova Helloworld Project

This guide is based on Hello World project which is generated by the following commands.

$ cordova create hello com.example.hello HelloWorld
$ cd hello
$ cordova platform add android

Install

Install coffee Command

$ npm install -g coffee

Install grunt-contrib-coffee
Grunt Plugin

$ npm install grunt-contrib-coffee --save-dev

Generate Working Tree

Transform www/js/index.js to src/www/js/index.coffee in example project. Because, we are gotta remote all the javascript file in folder
www/js/.

File src/www/js/index.coffee:

app =
initialize: () -> this.bindEvents() bindEvents: () ->
document.addEventListener 'deviceready', this.onDeviceReady, false onDeviceReady: () ->
app.receivedEvent 'deviceready' receivedEvent: (id) ->
parentElement = document.getElementById id
listeningElement = parentElement.querySelector '.listening'
receivedElement = parentElement.querySelector '.received' listeningElement.setAttribute 'style', 'display:none;'
receivedElement.setAttribute 'style', 'display:block;' console.log 'Received Event: ' + id

Update Gruntfile.coffee

module.exports = (grunt) ->
grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
coffee:
options:
bare: true
build:
expand: true
cwd: 'src/www'
src: ['**/*.coffee']
dest: 'www'
ext: '.js'
extDot: 'first' grunt.loadNpmTasks 'grunt-contrib-coffee'

Now We Have

  • src/ folder as coffee scripts location
  • src/www/js/index.coffee file that tranformed from www/js/index.js which is removed already.
  • Gruntfile.coffee build with coffee tasks
  • package.json which is updated with module grunt-contrib-coffee

Testing

$ grunt coffee
$ cordova install android

Get Cordova Ready for Grunt and CoffeeScript的更多相关文章

  1. 执行grunt命令报错 Cannot find module 'coffee-script'

    Failed to list grunt tasks in yudian-frontend-salesplatform\Gruntfile.js: process finished with exit ...

  2. ios cordova报gap://ready 弹出框,一直弹

    The iOS app was not working because there was a plugin missing: https://github.com/apache/cordova-pl ...

  3. Grunt 之 使用 JavaScript 语法检查工具 jshint

    前端开发环境准备好了,我们准备开始进行开发. 前端开发的主力语言是 JavaScript,这是一种脚本语言,没有编译器,也就没有了编译器带给我们的语法检查,怎样保证代码的质量呢?jshint 是一个强 ...

  4. emmet,jade,haml, slim,less,sass,coffeescript等的实战优缺点

    摘要: 文章背景,来自于群内周五晚上的一次头脑风暴式的思维碰撞交流活动. 随着前端技术的蓬勃发展, 各种新技术随着生产力的需要不断的涌入我们的视野, 那今天探讨的话题是这些新时代的前端兵器谱: 一. ...

  5. grunt快速入门

    快速入门 Grunt和 Grunt 插件是通过 npm 安装并管理的,npm是 Node.js 的包管理器. Grunt 0.4.x 必须配合Node.js >= 0.8.0版本使用.:奇数版本 ...

  6. VS2015+cordova+ionic安装配置

    VS2015已经出了正式版,想用来试一下cordova方面的开发.最近在看ionic这个框架,于是想能在VS2015里编辑js就好了. 下面说一下蛋疼的安装配置过程. 一.安装VS2015及Andro ...

  7. 前后端分离之前端项目构建(grunt+require+angular)

    前言 前段时间做了一个项目,前端开发页面,然后把代码给到后端同学,后端同学通过vm再来渲染页面.后来才发现,这种方式简直是太low了,因为前端代码在服务端同学那里,每次前端需要更改的时候都需要去到服务 ...

  8. 前端项目构建工具---Grunt

    什么是Grunt? grunt是javascript项目构建工具,在grunt流行之前,前端项目的构建打包大多数使用ant.(ant具体使用 可以google),但ant对于前端而言,存在不友好,执行 ...

  9. cordova IOS源码浅析

    cordova封装了一套js和OC通信的代码,cordova.js下的iOSExex是关键的js去调原生的发起点. function iOSExec() { var successCallback, ...

随机推荐

  1. [转]Centos6.5安装配置keepalived

    参考博文: Centos6.5安装配置keepalived CentOS6.5 keepalived详解及实现Nginx服务的高可用性 CentOS6.5 LVS + KeepAlived搭建步骤 我 ...

  2. 纪念一下第一次写的django代码

    @csrf_exemptdef new_project_detail(request):    if 'project_name' not in request.POST or 'project_po ...

  3. MapReduce调度与执行原理之任务调度(续)

    前言 :本文旨在理清在Hadoop中一个MapReduce作业(Job)在提交到框架后的整个生命周期过程,权作总结和日后参考,如有问题,请不吝赐教.本文不涉及Hadoop的架构设计,如有兴趣请参考相关 ...

  4. Delphi发送邮件...

    ///首先在控件栏定位到:Indy Clients加入控件IdSMTP ///再定位到:Indy Misc加入控件IdMessage ///发送邮件函数 procedure TForm1.SendMa ...

  5. C++变量(C++变量定义、变量赋值、命名规则)

    其实在前面的例子中已经多次用到了变量.在程序运行期间其值可以改变的量称为变量.一个变量应该有一个名字,并在内存中占据一定的存储单元,在该存储单元中存放变量的值.请注意区分变量名和变量值这两个不同的概念 ...

  6. java--继承的一些笔记

    public class Person { public void display(){ System.out.println("Play Person..."); } stati ...

  7. armeabi与armeabi-v7a

    原文http://blog.csdn.net/liminled/article/details/17030747 1.armeabi armeabi是指的该so库用于Arm的通用CPU. 2.arme ...

  8. highcharts dynamic change line color

    mouseOut: function(){ this.series.graph.attr({"stroke","#ccc"}) }

  9. 最小生成树(MST)[简述][模板]

    Prim(添点法) 1. 任选一点(一般选1), 作为切入点,设其与最小生成树的距离为0(实际上就是选一个点,将此树实体化),. 2. 在所有未选择的点中选出与最小生成树距离最短的, 累计其距离, 并 ...

  10. CF 319C(Kalila and Dimna in the Logging Industry-斜率DP,注意叉积LL溢出)

    C. Kalila and Dimna in the Logging Industry time limit per test 2 seconds memory limit per test 256 ...