Book Image

PhoneGap Beginners Guide (third edition)

Book Image

PhoneGap Beginners Guide (third edition)

Overview of this book

Table of Contents (22 chapters)
PhoneGap Beginner's Guide Third Edition
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Related Plugin Resources
Index

Time for action – optimizing JavaScript with RequireJS


Follow these steps to optimize the source code of your app using Node.js and RequireJS:

  1. Install the requirejs module using npm from the command-line tool:

    $ sudo npm install requirejs -g
    
  2. Go to the root folder of the app you worked on in the previous chapters, create a file named build.js, and add to it the build process configuration info (that is, the JavaScript folder, the paths to the library used in the project, the name of the main file of the app, and the output folder and filename):

    ({
        baseUrl: ‘js/',
        paths: {
            mustache: ‘libs/mustache',
            alice: ‘libs/alice.min',
            text: ‘libs/require/plugins/text'
        },
        name: ‘main',
        out: ‘js/main-built.js'
    })
  3. Open the command-line tool again and execute the following command in order to build the app:

    $ r.js -o build.js
    
  4. Open the index.html file and change the entry point of your app in the script tag in the header:

    <script data-main=”js/main-built” src=”js...