I’m unfortunately having difficulty deploying my ionic project for web. No matter what I do, commands such as 'ionic build, ‘ionic build --prod’, ‘ng build --prod’, or whatsoever always create a www folder that is incorrect. The index.html in this www folder is always blank when viewed from a browser.
I’ve tested this issue on other ionic projects as well (just generated some from templates) and the same issue occurs here, with the index.html in the www folder always being displaying a blank site. If possible, I’d appreciate any help if that’s OK!
ionic cordova platform add browser
ionic cordova run browser
ionic cordova build browser --prod
For testing purpose use ionic serve . It will rebuild automatically every time when you update your code.
have you changed the base href in index.html from
base href="/"
to
base href="."
Related
I created a flutter web application,
and I finished building it with the command ..
flutter build web --release ,
and then transferred it to a local server ,
The site does not work unless it is connected to the Internet ,
I want the site to work without an internet connection ,
As I work in an organization and some users do not have internet permissions .
Please, I want a solution to this problem .
Thanks
The problem is, that flutter has some dependencies, that can not be resolved when you, as the client, are offline. Mostly consisting of canvaskit and certain google fonts.
There are multiple solutions for that. The easiest being to use the html web-renderer:
flutter build web --release --web-renderer html
this should work for most applications, however it has lower performance than canvaskit, especially with high widget density.
Therefore you can also use canvaskit locally as it is automatically built when you build your release. But you have to set it as base url, by adding the following lines in your index.html:
<script>
window.flutterConfiguration = {
canvasKitBaseUrl: "/canvaskit/"
};
</script>
This makes sure your flutter application uses the local source for canvaskit. However, another problem could be the usage of google fonts, e.g. Roboto, as those often need to be downloaded as well. But you can just add those to the pubspec.yaml explicitly to account for that, like explained here.
Some sources for more informations:
flutter web-renderers
The same issue but on github
Making Flutter offline capable
Download and set locally from asset policy for your web application
Add link to local Canvaskit as bellow :
flutter build web --web-renderer=canvaskit
--dart-define=FLUTTER_WEB_CANVASKIT_URL=/canvaskit/
To make it work for a dev build, I incorporated Spanching's answer above in the following steps.
Run: flutter clean to clean up all build cache (this is important to have canvas kit re-downloaded in step 4 below).
Run: flutter pub get to download packages per pubspec.yaml
If you're using build runner: dart run build_runner build --delete-conflicting-outputs
At this stage you should have a clean /build folder (I also have an ios sub-folder as I'm also developing for iOS)
Run: flutter build web
At this stage you should have a clean /build/web added with a canvaskit folder underneath it. Full path: /build/web/canvaskit/
Then:
Open index.html under /web (note - do not open the one under /build/web)
Add the script mentioned in the answer above to the body of the html file. I just added it above the existing script that's already there.
Run your project in deubg mode (with Wifi turned off).
When I build my Ionic 4 app, it presumes to run at the root of the domain. It puts <base href="/" /> in the Index.html, and so all subsequent requests target the root of the domain. I can make it work in a folder by changing the base to <base href="." />, but a little voice tells me I shouldn't be modifying a generated file.
Where is the configuration variable to let me run my app from a folder if I want to? Do I need to know the name of the folder at build time?
You can just go ionic serve in any folder and it will serve your application. If you mean in an production environment you'd run ionic cordova build <platform> and it'll generate the .apk if you specified the android environment or it will generate an XCode project if you specified iOS.
I am however unsure which platform you are building for. So your results may vary if you're building for the browser platform.
Hope I understood your question correctly.
It's been a while since I developed in ionic ( 1 yr ). I think things have changed.
I used to be able to create a new blank template ionic project at a local folder on the mac and then replace its placeholder www folder with another project's www folder. This used to work.
Now, replacing the www folder in that ionic blank project makes no difference when I run any of these commands
ionic serve
cordova build ios
cordova emulate ios
I keep seeing the "The world is your oyster" message.
In fact, when I even renamed the local folder that was holding the entire ionic project, the cordova build ios still has worked without any complaints.
Clearly, the code is running somewhere else.
I also notice this at the terminal prompt:
➜ vb git:(master)
Here the git:(master) thing is new to me. Could this be the culprit?
If so, how can I disassociate the github aspect so I can work on the local and quickly test the changes I will be making in the local www as easy as going cordova build ios?
The problem was that when I created the blank project, I used the defaults which now outputs an ionic 2 baby.
I did the following 2 changes to solve my problem.
create my app for version 1 by appending --type=ionic1 as follows:
ionic cordova start myapp -blank --type=ionic1
I also prefixed allmy cordova commands with ionic name space.
Now I can replace the www all day long and my ionic cordova build ios & ionic cordova emulate ios will comply.
hope it will help someone.
I want to publish my app as PWA so what i did is
insert this script to index.html
<!--script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js')
.then(() => console.log('service worker installed'))
.catch(err => console.log('Error', err));
}
</script-->
then install
npm run ionic:build --prod
it looks like it deploy it but my questions are:
what files I need to upload to host for publish the app as PWA?
why when I change something in the app and run ionic serve nothing changed and it changed only in the index.html of the WWW folder? why?(because now it's PWA??)
when I open www folder and I run open index.html when i press on button that open alert dialog it not open that. why?
when I run the command? only in the end of development?
Run
ionic cordova platform add browser
ionic build browser --prod --release
Then go to [project_folder]/platforms/browser/www and copy the content at you http server.
Don't bother with Cordova for a PWA. Just use npm run build --prod and upload the /www folder.
PWA is more of a collection of concepts, so it's not just "on" or "off". At a minimum though you probably want to add a manifest file so you can make it more "app like" by hiding the browser frame, setting your icon, app name etc. Uncommenting the line to add service worker doesn't magically make it a PWA if you haven't put anything "useful" into service worker (which you may or may not need to do, depending on how your app works). Also note that you will need HTTPS to use a service worker.
You will also need to manually remove the line from index.html that includes cordova.js (which will be a 404 error if you just upload /www).
I use this command for building web app
ionic cordova build browser
Then copy the contents from IONIC-PROJECT/platforms/browser/www to the web server.
I am new to Ionic and just getting used to it. However I have noticed that when I create an app files are download from github such as:
Downloading:
https://github.com/driftyco/ionic-app-base/archive/master.zip
Often working without internet access is there a way that files I might need can be downloaded once and stored locally?
Yes, you can avoid downloading it with each new app. When you wrote something like to
$ ionic start YourAppName tabs
tabs - is an alias to Ionic starter repository. You can replace with relative or absolute path to a local directory.
Check out more about start parameters there - Starting an Ionic App.
EDIT: I don't see a reason why the code below couldn't work. And Yes, you have to unpack your default app files to some folder.
$ ionic start YourAppName c:\Temp\ionic-app-base-master
The command ionic start myApp will always create your project with the latest version of Ionic. It will always download the github. Currently there is no how to create a new project without using the downlod of the github.
You can create a blank project and uses it as "boilerplate project" (ionic start myApp blank). Then, when necessary, to update the Ionic (newest version) go to the root of your project and run ionic lib update.
Just download all the templates once and use it whenever you need when you are offline. Ionic will always download latest bundle when you do:
ionic start MyApp