I am getting ready to release my first app build in ionic. I am interested in how I can minify and uglify my code? Are there any plugins for that?
Thanks
uksz
Running ionic build --prod did the trick for me. I am using ionic to deploy my app as a website.
Using ionic cordova build <platform> --prod --release will create you a release version of the app with the code uglyfied and minified.
Also running a simple ionic cordova build <platform> will also do the job. The minified and uglyfied js is located on the www folder as main.js
Take in count that what minifies and uglyfies the source code is ionic-app-scripts.
There is an automated task runner for JavaScript called Gulp ( gulp.js ). It has packages like:
gulp-minify-css and gulp-uglify
Hope it helps.
Related
I need to modify cordova-plugin-media, but when I run app with ionic cordova run android my changes are not applied.
How should I modify and run plugin correctly?
I found the answer.
cordova files should be edited in /plugins folder, not in /node_modules
after editing, I should do: ionic cordova platform rm android and ionic cordova build android
After that modifications work.
You should paste some code, showing the code of app module and config.xml.
But basically you should only do:
ionic cordova plugin add cordova-plugin-media
npm install --save #ionic-native/media
And then add your plugin to the project into file
App.module.ts:
import { Media } from '#ionic-native/media';
...
providers: [
....
Media,
...
]
And that's it, then you should be able to use the functionalities inside your components.
I am new to Ionic, recently I developed One app.But my app size was 8mb.
How should I reduce app size,and I am not using any Images and plugins also, but it took 8mb size. please help me.
For production builds you can use ionic cordova build [android/ios] --prod --release. This can reduced the size of your application.
The prod and release flags will minify code and remove debugging utilities.
Documentation: https://ionicframework.com/docs/intro/deploying/#production-builds
You can use one of $ ionic cordova build options
--no-build - Do not invoke an Ionic build
--prod - Build the application for production
--aot - Perform ahead-of-time compilation for this build
--minifyjs - Minify JS for this build
--minifycss - Minify CSS for this build
--optimizejs - Perform JS optimizations for this build
...
For example: ionic cordova build android --prod --aot
I want to use Ionic deploy service in Ionic cloud.
When I run ionic upload command, a dev build is immediately triggered instead of prod build.
Is it possible to create a --prod build and upload?
One of major reasons is that multiple configurations in my code are bundled with --prod build only.
ionic upload --deploy=dev
[INFO] Running app-scripts build:
[09:55:59] build dev started ...
[09:55:59] clean started ...
[09:55:59] clean finished in 1 ms
You could pipe the npm scripts to run the ionic --prod first and then ionic upload
"scripts":{
"custom-upload":"ionic cordova build --prod | ionic upload"
}
and then run in the terminal
$: npm custom-upload
This will still run the dev build i think but your prod build should be packaged as well. It does not look like you can specify a build type in the ionic upload command, which makes me think that the ionic upload does not upload the production build to ionic view. And if that is that case then you might want to consider changing the configurations setup in a prod build to be set to only be used if not on localhost instead on based on the build.
I'm trying to figure out what's the best process to pass from the code to the final deployable apk/ipa.
So far I have a testsuite using Karma + Jasmine, which transpiles the TypeScript to JS and runs some unit tests. I start that process via gulp.
After that all I know is to ionic build android --release what generates (an unsigned yet) apk.
But I'm not sure of how ofuscated/minificated the generated apk is.
So, keeping in mind the code has to be as private as possible, is the minification and the ofuscation of the ionic build enough or should I do all those prebuild tasks manually via gulp?
And in that case, whats are the right tasks I should run, do I have to transpile all the TypeScript files to JS manually? and in what order should I run the tasks?
E.g. transpile -> tests -> minify -> uglify -> build apk or minify -> uglify -> transpile -> tests -> build apk
I'm a bit lost with this, and the only thing I can figure out is that the tests should be ran first, because is case of test failure the process should be aborted.
Try ionic-app-scripts >= 0.0.48 to config build.
Production:
ionic build android --prod
To check the minified file, open the apk file with GNOME Archive Manager (or similiar) and extract /assets/www/build/js/app.bundle.js file.
Preparing an Ionic Cordova app for release in production
1. Building
In your terminal execute the following command according to your platform (android / ios):
ionic build android --prod --release
2. Releasing
In order to be able to install a production application on a device and furthermore in order to be able to publish it in app stores, your .apk or .ipa
file needs to be signed. How you do that depends on the platform.
Here is the procedure in detail for Android and for iOS.
Preparing an Ionic Progressive Web App (PWA) for release in production
1. Building
In your package.json file, you should make sure to have something like the following:
"scripts": {
// ...
"build:www": "rm -rf www && ionic-app-scripts build --prod",
// ...
},
Now in your terminal run:
npm run build:www
2. Releasing
Your app is built in the folder www ready for you to serve in production using any webserver like NginX, Apache or a custom Node + Express webserver.
Valid as of Ionic v3.3
Learn more about ionic-scripts, what they do and which other scripts you could possibly find useful.
I'm starting to learn Ionic2, I have created a new project with ionic start myproject --v2 and everything works correctly if I do ionic serve.
The build folder is missing in ionic 2 project folder.
Whenever I am trying to download any existing Ionic2 template in that one also build folder missing.
ionic -v 2.0.0-beta.30
cordova -v 6.2.0
node -v v6.2.1
npm -v 3.9.5
your ionic serve build is under www. The native builds ( from ionic build) are under platform.
A little late but I had the same issue and was able to fix it by installing Gulp :
npm install -g gulp
Then I did gulp build.
This solved my issues and generated the build folder as it was supposed to.
First you need to add support for the platform/s you are working with, by executing from Ionic CLI console:
ionic platform add android
or
ionic platform add ios
And then you should build your project by executing:
ionic build android
or
ionic build ios