Miquel
Miquel

Reputation: 8969

Change cordova www location

I'm using a script which is being ran before_prepare. The script lints, annotates, minifies, concatenates, creates templates cache for any html template, etc in a cordova - ionic app.

This script is placing all output in a www-build folder, sibbling to www (but it can be placed wherever is needed):

├── www
│   ├── css
│   │   └── style.css
│   ├── img
│   │   └── logo.png
│   ├── index.html
│   ├── js
│   │   ├── app.js
│   │   ├── audit
│   │   └── tabs
│   ├── lib
│   │   └── ionic
│   ├── manifest.json
│   └── service-worker.js
└── www-build
    ├── all.min.css
    ├── all.min.js
    ├── img
    │   └── logo.png
    ├── index.html
    ├── lib
    │   └── ionic
    └── manifest.json

I'm wondering if there is a way to tell cordova to use this new www-build folder at runtime (during cordova prepare) to get all files to copy to platform assets. Maybe if its not at runtime, is there any static way?

Right now I'm hooking after_prepare and deleting the assets cordova prepared and copying the new ones to each platform, but I'm wondering if this is a good practice.

Upvotes: 0

Views: 602

Answers (2)

Miquel
Miquel

Reputation: 8969

Following the idea of @johnborges response My solution has been to make the script do the following steps:

Before prepare:

  • Move www/ to src/
  • Process src/ to www/ (lint, compress, concat, annotate, etc.)

After prepare:

  • Delete www/
  • Move src/ back to www/

In this way the scripts copied to platform are the processed ones, and it does work with phonegap serve.

Upvotes: 0

johnborges
johnborges

Reputation: 2533

Cordova looks in /www by default. I don't think this can be changed. Why not just have all your source code in a new directory /src and then have your built code placed in /www?

├── src
│   ├── css
│   │   └── style.css
│   ├── img
│   │   └── logo.png
│   ├── index.html
│   ├── js
│   │   ├── app.js
│   │   ├── audit
│   │   └── tabs
│   ├── lib
│   │   └── ionic
│   ├── manifest.json
│   └── service-worker.js
└── www
    ├── all.min.css
    ├── all.min.js
    ├── img
    │   └── logo.png
    ├── index.html
    ├── lib
    │   └── ionic
    └── manifest.json

Upvotes: 1

Related Questions