Ionic Pro not building with --prod flag


#1

Hi,

I’m uploading latest codebase to Github. Ionic Pro picks it up, but it’s building without --prod flag, like Ionic serve. So my auto deploy is a dev build that runs super slow. This has never happened before. Any advice?

Build log below

Running with gitlab-ci-multi-runner 9.1.0 (0118d89)
on ip-10-2-1-242 (c9648220)
Using Shell executor…
Running on ip-10-2-1-242…
Cloning repository…
Cloning into ‘/home/gitlab-runner/builds/c9648220/1/media4learning/cpg’…
Checking out 86848742 as master…
Updating/initializing submodules recursively…
$ run “fetch-updates”
Running Stage fetch-updates for Job: 5543042
Checking for build process updates…
$ run “build-app”
Running Stage build-app for Job: 5543042
Parsing ionic.config.json for project settings
Project Settings:
Name: CPGs
App ID: *hidden due to zero security of bundles
Type: ionic-angular
Build script detected in package.json…
$ npm install --quiet --no-optional
WARN notice [SECURITY] tunnel-agent has 1 moderate vulnerability. Go here for more details: https://nodesecurity.io/advisories?search=tunnel-agent&version=0.4.3 - Run npm i npm@latest -g to upgrade your npm version, and then npm audit to get more info.
WARN notice [SECURITY] lodash has 1 low vulnerability. Go here for more details: https://nodesecurity.io/advisories?search=lodash&version=3.10.1 - Run npm i npm@latest -g to upgrade your npm version, and then npm audit to get more info.
WARN notice [SECURITY] randomatic has 1 low vulnerability. Go here for more details: https://nodesecurity.io/advisories?search=randomatic&version=1.1.7 - Run npm i npm@latest -g to upgrade your npm version, and then npm audit to get more info.
WARN notice [SECURITY] mime has 1 moderate vulnerability. Go here for more details: https://nodesecurity.io/advisories?search=mime&version=1.3.4 - Run npm i npm@latest -g to upgrade your npm version, and then npm audit to get more info.
WARN notice [SECURITY] hoek has 1 moderate vulnerability. Go here for more details: https://nodesecurity.io/advisories?search=hoek&version=2.16.3 - Run npm i npm@latest -g to upgrade your npm version, and then npm audit to get more info.

node-sass@4.7.2 install /usr/src/app/node_modules/@ionic/app-scripts/node_modules/node-sass
node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.7.2/linux-x64-57_binding.node
Download complete
Binary saved to /usr/src/app/node_modules/@ionic/app-scripts/node_modules/node-sass/vendor/linux-x64-57/binding.node
Caching binary to /home/gitlab-runner/.npm/node-sass/4.7.2/linux-x64-57_binding.node

node-sass@4.8.3 install /usr/src/app/node_modules/node-sass
node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.8.3/linux-x64-57_binding.node
Download complete
Binary saved to /usr/src/app/node_modules/node-sass/vendor/linux-x64-57/binding.node
Caching binary to /home/gitlab-runner/.npm/node-sass/4.8.3/linux-x64-57_binding.node

uglifyjs-webpack-plugin@0.4.6 postinstall /usr/src/app/node_modules/@ionic/app-scripts/node_modules/uglifyjs-webpack-plugin
node lib/post_install.js

uglifyjs-webpack-plugin@0.4.6 postinstall /usr/src/app/node_modules/webpack/node_modules/uglifyjs-webpack-plugin
node lib/post_install.js

node-sass@4.7.2 postinstall /usr/src/app/node_modules/@ionic/app-scripts/node_modules/node-sass
node scripts/build.js

Binary found at /usr/src/app/node_modules/@ionic/app-scripts/node_modules/node-sass/vendor/linux-x64-57/binding.node
Testing binary
Binary is fine

node-sass@4.8.3 postinstall /usr/src/app/node_modules/node-sass
node scripts/build.js

Binary found at /usr/src/app/node_modules/node-sass/vendor/linux-x64-57/binding.node
Testing binary
Binary is fine
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})

added 1348 packages in 37.554s
$ npm install --quiet --no-optional success
$ npm run build
npm info it worked if it ends with ok
npm info using npm@5.3.0
npm info using node@v8.2.1
npm info lifecycle CPGs@1.1.0~prebuild: CPGs@1.1.0
npm info lifecycle CPGs@1.1.0~build: CPGs@1.1.0

CPGs@1.1.0 build /usr/src/app
ionic-app-scripts build

[11:09:41] ionic-app-scripts 3.1.9
[11:09:41] build dev started …
[11:09:41] clean started …
[11:09:41] clean finished in 1 ms
[11:09:41] copy started …
[11:09:41] deeplinks started …
[11:09:42] deeplinks finished in 398 ms
[11:09:42] transpile started …
[11:09:47] transpile finished in 5.12 s
[11:09:47] preprocess started …
[11:09:47] preprocess finished in 1 ms
[11:09:47] webpack started …
[11:09:47] copy finished in 5.80 s
[11:09:56] webpack finished in 8.91 s
[11:09:56] sass started …
Without from option PostCSS could generate wrong source map and will not find Browserslist config. Set it to CSS file path or to undefined to prevent this warning.
[11:09:57] sass finished in 1.34 s
[11:09:57] postprocess started …
[11:09:57] postprocess finished in 18 ms
[11:09:57] lint started …
[11:09:57] build dev finished in 16.03 s
[11:10:01] lint finished in 4.16 s
npm info lifecycle CPGs@1.1.0~postbuild: CPGs@1.1.0
npm info ok
$ npm run build success
Generating app manifest…
$ ionic deploy manifest
$ ionic deploy manifest success
Uploading app files…
Uploading manifest…
Manifest uploaded successfully!
Uploading build…
Build uploaded successfully!
Running after script…
$ run “clean-up”
Running Stage clean-up for Job: 5543042
Job succeeded


#2

Ok so --prod isn’t default for Ionic Pro. I really think it should be. This is an old project and the build script didn’t include the --prod flag. If anyone else has this issue, check you package.json build command. It’s likely missing --prod.


#3

The --prod flag is very picky animal. My advice is to manually clean your code beforehand. Some of your pages/services might have loaded a module that is not necessary. The ionic serve gives you just very polite lint message that something is loaded/defined but never used but the ionic cordova build ....... --prod is about optimise and tree-shake the whole code (typically from 6MB down to 2.3MB).
I believe the build error occurs when the tree-shaking algoritmus is not capable to decide which copy of module to use.