Ionic starter project based on generator-gulp-angular generated code. When in doubt how to use this project reference Gulp Angular Generator documentation.
Install the necessary dependencies in the project folder.
$ npm install
$ bower install
App module name is "starter". If you want to use this as a skeleton for your Ionic project
- Find all occurrences of
starterin JS and JSON files - Replace
starterthem with your project name. - Open
index.htmland replaceng-app="starter"with your project name.
Since Ionic 2 and Angular 2 are just around the corner I don't see the need to create a Yeoman generator.
Best Practice Recommendations for Angular App Structure
- The project uses "Best Practice Recommendations for Angular App Structure". It's important to read the recommendations. Don't omit this step.
- Unit tests are named *.specs.js and *.mock.js and are located in the respective components folders.
- You'll have the default Ionic Starter Project implemented in the Angular best practices. Do follow this structure. You'll find it rewarding when working on large projects.
Warning: the first file of a type in a folder is often missed by the Gulp watch, try to relaunch Gulp if it happens.
List of features included in the project:
- SASS
- bower to manage dependencies
- ng-cordova (no cordova plugins installed, only the js library)
- ionic
- eslint
- Unit tests with Karma and Jasmine
Bower JSON is updated to include all the necessary overrides for the project to work out of the box without the need for you to change anything.
Use Gulp tasks
gulporgulp buildto build an optimized version of your application in /distgulp serveto launch a browser sync server on your source filesgulp serve:distto launch a server on your optimized applicationgulptest to launch your unit tests with Karmagulp test:autoto launch your unit tests with Karma in watch modegulp protractorto launch your e2e tests with Protractorgulp protractor:distto launch your e2e tests with Protractor on the dist files
More information on the gulp tasks in Gulp Angular Generator User Guide .
You can test locally by using gulp serve. It runs with BrowserSync.
There is a mocked cordova.js in src/mocks folder. It will be served instead of the original cordova.js when testing in the browser.
When developing a Cordova app you'll need CORS turned off. On Chrome you can do this in 2 ways:
-
Add
--disable-web-security --user-data-dirto you Chrome shortcut. Before testing kill all chrome tasks and then run the browser againOR
-
Install a CORS disabling extension from the Chrome Store.
You'll notice that www folder doesn't exist. This folder is required for your Cordova app to run.
Run gulp build to generate the www folder.
You'll need to always run gulp build before running ionic run or build tasks.
Example:
$ gulp build
$ ionic run ios
There is included support for angular-translate if you need localization. To use angular-translate
- Install the library:
$ bower install angular-translate --save - Create
localefolder insrc/app - For each language create a locale JSON. Name format is
locale-<LANGUAGE>.json. Example:locale-en.json,locale-de.json - Open
src/app/index.module.jsand uncommentpascalprecht.translate.
Run gulp serve. There is already an existing locale gulp task. It will generate a javascript file from all your JSON files.
You don't need to load the JSON files manually.
As already mentioned, there is a mocked cordova.js - app/src/mocks/cordova.js.
Mock any Cordova module you need in this file. This will ensure you can continue testing in the browser without errors.
There is one mocked Cordova plugin used by $cordovaAppVersion.