You may reference to below if you deside to work with coffee instead of Javascript in Cordova 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
$ npm install -g coffee
$ npm install grunt-contrib-coffee --save-dev
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
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‘
src/
folder as coffee scripts locationsrc/www/js/index.coffee
file that tranformed from www/js/index.js
which is removed already.Gruntfile.coffee
build with coffee taskspackage.json
which is updated with module grunt-contrib-coffee
$ grunt coffee
$ cordova install android
Get Cordova Ready for Grunt and CoffeeScript,布布扣,bubuko.com
Get Cordova Ready for Grunt and CoffeeScript
原文:http://blog.csdn.net/wxqee/article/details/34989361