Giter VIP home page Giter VIP logo

gulp-ionic-webbuild's Introduction

gulp-ionic-webbuild

Add-on Gulp tasks to optimise an Ionic project for mobile web deployment.

Installation

From your Ionic project directory, run:

npm i --save-dev gulp-ionic-webbuild

Next, at the bottom of your gulpfile.js, add the following:

require('gulp-ionic-webbuild')(gulp, {
  templatesModule: 'templates'
});

Note: the templatesModule value is the name of the Angular module to which the compiled templates will be added (this defaults to "templates"). It's very important that this matches the name of an Angular module included in your app, otherwise things will break in spectacular fashion!

Finally, add special "marker" comments to the <head> section of your www/index.html file. These comments will inject your compiled AngularJS templates/partials (using gulp-angular-templatecache) and generate a single optimised JS build file (using gulp-useref and gulp-uglify).

...
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
  <title></title>

  <!-- compiled css output -->
  <link href="css/ionic.app.min.css" rel="stylesheet">

  <!-- build:js({www,www-dist/partials}) js/app.build.js -->
  <!-- ionic/angularjs js -->
  <script src="lib/ionic/js/ionic.bundle.js"></script>

  <!-- cordova script (this will be a 404 during development) -->
  <script src="cordova.js"></script>

  <!-- bower deps -->
  <script src="lib/lodash/lodash.js"></script>
  <script src="lib/moment/moment.js"></script>

  <!-- your app's js -->
  <script src="js/app.js"></script>
  <script src="js/controllers.js"></script>

  <!-- inject:partials -->
  <!-- endinject -->
  <!-- endbuild -->
</head>
...

The important bits to notice here are:

<!-- build:js({www,www-dist/partials}) js/app.build.js -->

This marks the starting point from which files will be included in the JS build.

<!-- inject:partials -->
<!-- endinject -->

This is where your compiled templates will be injected into the file. Since this will be a JS file, it will also be included in the final build.

<!-- endbuild -->

This denotes the end point for files to be included in the JS build.

Usage

Simply run your new Gulp task from your Ionic project directory:

gulp build-web

Your compiled web build can now be found in the www-dist folder. You can test it out using a web server of your choice, e.g.:

npm i -g http-server
http-server www-dist

gulp-ionic-webbuild's People

Contributors

dylansmith avatar

Watchers

Jason Girdner avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.