ionic - change path of index.html - javascript

I have used the generator of app ionic start myApp blank as a start point.
But now I have special requirements of code's structure.
I must place in a same group the resource of the same type.
js directory for just js files
html directory for html files
and so on...
The problem here is index.html, I must move it from www directory to www/html directory, how can I achieve it?

Related

How can I disable conversion of .json/.webmanifest url into base64 string?

I have a problem that has been bothering me for a while now. I have a vite-react-typescript project in VSCode, with a link in the index.html page to a webmanifest. This is basically a json file with a different extention.
When I build my app, the index.html output file contains the meta tag, however instead of referencing the path of the .webmanifest file, it has converted the entire file into base64. Because of this some browsers cannot find the .manifest file and therefore the website cannot be installed as a PWA.
I assume the problem/possible solution lies in the compiler/build options of vite, however I don't know how to fix this auto-conversion.
Here is the github repo: https://github.com/PluginDev-A/Website
the compiled index.html file is in the dist directory, the original index.html file is in the main directory. The problem is on line 6 of both files
**It does not matter whether the file-extention is .json or .webmanifest, both urls get converted upon build
That file should be probably placed in public directory because it is:
Never referenced in source code (e.g. robots.txt)
Must retain the exact same file name (without hashing)
And it should be referenced from index.html with absolute path
<link rel="manifest" href="/manifest.webmanifest">

change absolute path to relative using gulp

In my gulp workflow I have a task that uses npm browser-sync module to serve static files. One of the options of this module is able to set a base directory to let me call js/css/img files etc, and include it using an absolute path like this:
<img src="/imgs/label.png">
this feature let me call this file from any subdirectory I want
/public
---/imgs
------label.png
---/catalog
------list.html <--- here
---index.html <--- and here, this image called using the same path /imgs/label.png
this works fine. Otherwise, I have a task that builds the final compressed and minified version of static files. The problem is, that when gulp building a dist folder with that files that located in the public folder, in html files, there's still absolute path in attributes like href/src. I need to convert the absolute path into relative with keeping a folder structure. I mean that in index.html src has to be imgs/label.png, and in catalog/list.html the same src attribute has to be ../imgs/label.png. Question: is there any module that able to do this for me, or maybe there's some another way to do that, instead of replacing the paths with own hands? Any advice would be appreciated.

Linking a local copy of bootstrap

So Im trying to link a local copy of bootstrap (It works with a CDN). I have bootstrap.css installed in the same directory as index.ejs and yet I keep getting these 404 errors.
So the file path for bootstrap.css is /home/daniel/scheduler/doc_display/app/bootstrap.css
and index is: /home/daniel/scheduler/doc_display/app/index.ejs
Any help would be much apreciated
Your browser is going to look for the file relative to the location of the page it loads, so you need to make sure your path is correct.
Right now it's looking for it in the same folder as the index, which it looks like isn't where it's located.
I put the bootstrap.css file inside of my dist directory then included the new path inside the link tag. For some reason webpack seems to find paths when they are in the dist directory

gh-pages ignoring project directory when searching for resources?

I have a website I have been working on that works just fine locally but when deployed to gh-pages has many 404's when trying to pull in resources.
For example, I have a line of css for the background which is
background: #fff url(/assets/images/bg.jpg) repeat top left;
the 404 I get is this{
github.io/assets/images/bg.jpg
The path should be
github.io/myProject/assets/images/bg.jpg
How can I change this to work?
What is happening is that in your local setup the assets folder is in the same directory.
Lets say your local path looks someting like this:
file:///index.html where your assets folder is a sibling to index.html. In this case it works because / goes to the beggining of the directory. which in this case is : file:/// and there it see's the assets folder so it works locally.
On github now, you have a repo which is basically my-project. In my-project you have index.html and the folder assets. So when you say /assets/ here the begginnig directory is github.io so it looks for assets there which obviously doesn't exist.
Solution
Dont add / before assets. As long as assets is in the same directory as where this code is written you should be fine.
Also take a closer look at relative paths to understand it better: http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/
While gh-pages are generated by Jekyll, you can use his magic to ease development.
Create a _config.yml file at the root, containing :
baseurl: myProject/
You can now call any resource with {{site.baseurl}}assets/images/bg.jpg
which will automatically translate to myProject/assets/images/bg.jpg.

How do you change file paths in Angular app?

I'm looking at this sample Angular application.
In the index.html file, there are lines like
<script type="text/javascript" src="/static/angular.js"></script>
However, upon closer inspection there are no folders in the project called static.
How does this work? How does angular locate these references?
Angular has nothing to do with this. It is the express server which takes care of the paths.
Take a look at server/config.js. You will see staticUrl: '/static' mentioned there.
Now open server/server.js (server.js is the script which runs before anything else runs in the app so all the configuration is done within this file) and on line 21 you will see require('./lib/routes/static').addRoutes(app, config);. This requires the static.js file which instructs the app to use /static (mentioned in the config.js file) as the path for static files such as CSS and javascript files.
This is a server side phenomenon. There is a middleware in this file server/lib/routes/static.js :
line : 9
app.use(config.server.staticUrl, express.static(config.server.distFolder));
What this does is : if any http request is started from config.server.staticUrl (whitch is /static for this app) the server tries to respond with the resource that are kept in a config.server.distFolder folder (which is client/dist for this app).
For example :
when you request to this url /static/angular.js the middleware tries to find angular.js file in client/dist/. Because client/dist directory is mapped to the url which starts with /static by the middleware.
When that HTML file is processed by the browser, the layout engine is making a separate HTTP request to the server to download the resource in question:
/static/angular.js
Since all of that is handled by the server routing mechanism there doesn't have to be a folder named static in client code. Your example is using Node.js Express routing which maps /static routes to actual physical paths.
Here is a piece of code that configures static routes:
https://github.com/angular-app/angular-app/blob/master/server/config.js
The important parts are:
staticUrl: '/static', // The base url from which we serve static files (such as js, css and images)
And the destination folder that /static maps to:
distFolder: path.resolve(__dirname, '../client/dist'), // The folder that contains the application files (note that the files are in a different repository) - relative to this file
Per the documentation the dist folder contains the Grunt build results, and if you take a look at the gruntfile you will find all the grunt configuration that makes this possible.
https://github.com/angular-app/angular-app/blob/master/client/gruntFile.js

Categories