Skip to content

Instantly share code, notes, and snippets.

@smarlhens
Last active September 10, 2018 09:43
Show Gist options
  • Save smarlhens/5cd31ab26f07c5e5d5ebaad8115dc55e to your computer and use it in GitHub Desktop.
Save smarlhens/5cd31ab26f07c5e5d5ebaad8115dc55e to your computer and use it in GitHub Desktop.
Create an app with Cordova/Angular 6

Create Angular app

npm i -g @angular/cli 
ng new app-name
cd app-name

Create Cordova app

cordova create folder-name tld.company.app-name app-name
cordova platform add platform-name

Configuration

Add scripts folder in folder-name.
Create a file : prepareAngularApp.js
Content :

const fs = require('fs');
const execSync = require('child_process').execSync;

module.exports = function(context) {
    console.log('Building Angular application into "./www" directory');
    const basePath = context.opts.projectRoot;
    const baseWWW= basePath + '/www';

    console.log(execSync(
        "ng build --prod --output-hashing none  --delete-output-path true --output-path cordova/www/ --base-href .",
        {
            maxBuffer: 1024*1024,
            cwd: basePath + '/..'
        }).toString('utf8')
    );
    var files = fs.readdirSync(baseWWW);
    for (var i = 0; i < files.length; i++) {
        if (files[i].endsWith('.gz')) {
            fs.unlinkSync(baseWWW + '/' + files[i]);
        }
    }
    fs.writeFileSync(baseWWW + '/.gitignore', `# Ignore everything in this directory
*
# Except this file
!.gitignore
`);
};

Build Angular app for Cordova

ng build --prod --output-hashing none  --delete-output-path true --output-path cordova/www/ --base-href .

Build Cordova app

cordova build platform-name
cordova run platform-name --device
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment