首页 > 代码库 > Get Cordova Ready for Grunt and CoffeeScript
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 folderwww/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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。