Get Cordova Ready for Grunt and CoffeeScript
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 locationsrc/www/js/index.coffee
file that tranformed fromwww/js/index.js
which is removed already.Gruntfile.coffee
build with coffee taskspackage.json
which is updated with modulegrunt-contrib-coffee
Testing
- $ grunt coffee
- $ cordova install android
Get Cordova Ready for Grunt and CoffeeScript的更多相关文章
- 执行grunt命令报错 Cannot find module 'coffee-script'
Failed to list grunt tasks in yudian-frontend-salesplatform\Gruntfile.js: process finished with exit ...
- ios cordova报gap://ready 弹出框,一直弹
The iOS app was not working because there was a plugin missing: https://github.com/apache/cordova-pl ...
- Grunt 之 使用 JavaScript 语法检查工具 jshint
前端开发环境准备好了,我们准备开始进行开发. 前端开发的主力语言是 JavaScript,这是一种脚本语言,没有编译器,也就没有了编译器带给我们的语法检查,怎样保证代码的质量呢?jshint 是一个强 ...
- emmet,jade,haml, slim,less,sass,coffeescript等的实战优缺点
摘要: 文章背景,来自于群内周五晚上的一次头脑风暴式的思维碰撞交流活动. 随着前端技术的蓬勃发展, 各种新技术随着生产力的需要不断的涌入我们的视野, 那今天探讨的话题是这些新时代的前端兵器谱: 一. ...
- grunt快速入门
快速入门 Grunt和 Grunt 插件是通过 npm 安装并管理的,npm是 Node.js 的包管理器. Grunt 0.4.x 必须配合Node.js >= 0.8.0版本使用.:奇数版本 ...
- VS2015+cordova+ionic安装配置
VS2015已经出了正式版,想用来试一下cordova方面的开发.最近在看ionic这个框架,于是想能在VS2015里编辑js就好了. 下面说一下蛋疼的安装配置过程. 一.安装VS2015及Andro ...
- 前后端分离之前端项目构建(grunt+require+angular)
前言 前段时间做了一个项目,前端开发页面,然后把代码给到后端同学,后端同学通过vm再来渲染页面.后来才发现,这种方式简直是太low了,因为前端代码在服务端同学那里,每次前端需要更改的时候都需要去到服务 ...
- 前端项目构建工具---Grunt
什么是Grunt? grunt是javascript项目构建工具,在grunt流行之前,前端项目的构建打包大多数使用ant.(ant具体使用 可以google),但ant对于前端而言,存在不友好,执行 ...
- cordova IOS源码浅析
cordova封装了一套js和OC通信的代码,cordova.js下的iOSExex是关键的js去调原生的发起点. function iOSExec() { var successCallback, ...
随机推荐
- Android 四种启动模式 已看晕
http://blog.csdn.net/zdw890412/article/details/7386314 //有点乱 http://www.cnblogs.com/fanchangfa/arch ...
- phpmailer发送邮件,可以带附件
先从网上下载phpmailer压缩包 将解压的文件导入到你的项目中 实例 require_once ('PHPMailer/class.phpmailer.php'); //引入phpmailer文件 ...
- javacoo/CowSwing 丑牛迷你采集器
丑牛迷你采集器是一款基于Java Swing开发的专业的网络数据采集/信息挖掘处理软件,通过灵活的配置,可以很轻松迅速地从 网页上抓取结构化的文本.图片.文件等资源信息,可编辑筛选处理后选择发布到网站 ...
- 使用adb签名并安装Android程序
首先需要准备Android SDK包,我是在windows上操作的,在PATH中配置 YOUT_SDK_PATH\android-sdk-windows\platform-tools 和 YOUT ...
- MySQL中关于日期、时间的数据类型和函数
一.日期相关的数据类型 1.datetime 占用8字节,既显示了日期,又显示了时间.其表示的日期范围为“1000-01-01 00:00:00”到“9999-12-31 23:59:59” 2.da ...
- Android --Vibrator--震动服务
1.取得震动服务的句柄 vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);或者vibrator = (Vibrator)getAppli ...
- WebView使用详解
一.用WebView处理页面导航 可以加载本地资源也可以加载web资源,区别是我们要加载本地资源要实现在assets文件夹里添加一个.html资源.调取网页的时候可以用loadUrl方法把网址添加进去 ...
- c#--foreach遍历的用法与split的用法
一. foreach循环用于列举出集合中所有的元素,foreach语句中的表达式由关键字in隔开的两个项组成.in右边的项是集合名,in左边的项是变量名,用来存放该集合中的每个元素. 该循环 ...
- Python 第六篇(中):面向对象编程中级篇
面向对象编程中级篇: 编程思想概述: 面向过程:根据业务逻辑从上到下写垒代码 #最low,淘汰 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 #混口饭吃 def add(ho ...
- 关于UIText换行
话不多说,直接上代码 --代码是lua的,c++也一样 local text = ccui.Text:create("text can line wrap text can line wra ...