Building for PWA only


#1

Basically I use a single code base to create a PWA and also build for Cordova.

I have some cordova plugins, which are all wrapped in an if statement, e.g

if(this.platform.is('cordova')) {...}

The only thing is for when I deploy as a PWA it means that all the cordova plugins are still included in the vendor.js file, even after using --prod (which takes the bundle from 7mb~ -> 2mb~) this is still quite considerably large and all unnecessary as the cordova plugins won’t be needed in the PWA.

Has anybody faced this issue and how did they get around producing a smaller bundle?


#2

What exact command are you using to build?
What is your ionic info output?


#3
npm run build --prod

ionic info:

michael$ ionic info

cli packages: (/Users/michael/Dropbox/ionic-project/node_modules)

    @ionic/cli-utils  : 1.13.1
    ionic (Ionic CLI) : 3.13.2

global packages:

    cordova (Cordova CLI) : 7.1.0

local packages:

    @ionic/app-scripts : 3.0.0
    Cordova Platforms  : ios 4.5.1
    Ionic Framework    : ionic-angular 3.7.1

System:

    ios-deploy : 1.9.2
    ios-sim    : 6.1.2
    Node       : v8.3.0
    npm        : 5.3.0
    OS         : macOS Sierra
    Xcode      : Xcode 9.0.1 Build version 9A1004

Misc:

    backend : legacy

Michaels-MacBook-Pro:funbid-webapp michael$ ionic info

cli packages: (/Users/michael/PATH/node_modules)

    @ionic/cli-utils  : 1.13.1
    ionic (Ionic CLI) : 3.13.2

global packages:

    cordova (Cordova CLI) : 7.1.0

local packages:

    @ionic/app-scripts : 3.0.0
    Cordova Platforms  : ios 4.5.1
    Ionic Framework    : ionic-angular 3.7.1

System:

    ios-deploy : 1.9.2
    ios-sim    : 6.1.2
    Node       : v8.3.0
    npm        : 5.3.0
    OS         : macOS Sierra
    Xcode      : Xcode 9.0.1 Build version 9A1004

Misc:

    backend : legacy

#4

I have no experience with this, but could you try ionic build --prod and npm run ionic:build --prod? Might be they do the exact same as the one you are using - or not.


#5

My npm build:

"build": "ionic-app-scripts build && npm run generate:cache-manifest",

It just runs the normal app scripts build & also runs another script to generate a cache list for service worker.

I may be wrong, but I thought this was the expected behaviour. That the cordova plugins are included in your bundles even if you’re not build for ios/android?
I’m just asking to see if anybody has been able to skip these from being included when they’re not building for cordova


#6

I am not sure Cordova plugins are included in the bundle at all to be honest, but don’t have the time to investigate right now how the Cordova plugin JS actually is put into index.html.

They are in node_modules, but not used or referenced anywhere in the Ionic (Native) code afaik. They “magically” appear in the global namespace in a Cordova build, my guess owuld have been via cordova.js that is included in index.html.