When running a Meteor application the assets in <script> tags are relative to the root path, like <script type="text/javascript" src="/app/routes.js?baa7082cd1947c1ebf3cdabc08bfe8701bd770af"></script>
I'm trying to point an nginx server to it from a different path, e.g.example.com/my-app but since the assets are still pointing relative to the root path they don't get loaded.
E.g. example.com/app/routes.js instead of example.com/my-app/routes.js
In webpack I could just specify a publicPath and the assets will point relative to it. Is there something similar that I can do in Meteor?
The files should be in public directory in the root.
For example if the structure is public/images the src of image will be /images/imagefile.jpg. Same for javascript.
The files can be referred as /assets/public/images
Related
Trying to change the font in styles.css file in GitHub pages, here is the code:
#font-face {
font-family: "Samim";
src: url("/resources/Samim.ttf") format("truetype");
}
Here is the directory and font saved in resources folder
project files directory
the problem is that font doesn't change, also tried to move the font to main directory but no change, it also works properly locally on vscode live preview.
You have to provide the Relative Path to the file,
For Example Take This Directory Structure:
- root
- system-files
- vahid
- github-pages
- resources
- Samim.ttf
- README.md
- index.html
- styles.css
Here the "root" is the Drive On which your Operating System is Stored On, and "system-files" contains your Operating System's Important Files and finally you have this folder "vahid" which contains the user's files, and inside "vahid" you have "github-pages" folder where all your github pages code is stored.
In Path the / means the root, in Windows take this as like if you open C:\ in Windows Explorer.
And this period . means current directory, and when you use ./ instead of / you're specifying a path to a file/folder in current Directory.
Now when in my styles.css if I use this Path /resources/Samim.ttf what it means is "Samim.ttf" File in inside of the "resources" folder in the root directory.
Did you notice something? Let me try to show this path in the directory Structure.
- root
- resources
- Samim.ttf
As you can see the Path we specified doesn't exist, try to compare it to the Real Directory Structure Given Above.
So instead of using / we have to use ./ because the "resources" folder is in the same folder as of the "styles.css".
So you have to replace your Absolute Path with Relative Path, which will be this:
./resources/Samim.ttf
Read More About Relative And Absolute Path At LinuxHandBook.com
I changed the directory path like this:
url("./resources/Samim.ttf")
just added one . after /, idk why but it works now!
also trided ../resources , ..resources and /resources and didn't worked.
Docs that there is a possibility to use src folder in Next.js.
I think this is a good pattern to separate actual business logic from app configs.
It would feel natural to me to put the public folder also under the src folder.
No. The public folder has to be in root folder
Config files like next.config.js and tsconfig.json should be inside the root directory, moving them to src won't work. Same goes for the public directory
My dev server is running on node live-server. My prod will be a LAMP server.
I have normalize.css inside my node_modules server.
In my index.html I have
<link rel="stylesheet" href="/node_modules/normalize.css">
<link rel="stylesheet" href="css/styles.css">
I don't want files linked to node_modules directory.
I want something like
<link rel="stylesheet" href="css/normalize.css">
Is this doable? I have lot of other css and js files like this.
Update 1
Let me clarify, this app is not a node app nor a php app, It has only html, css and js files. Everything runs on client side, But.. we want to leverage the latest client side dev tools for JS and CSS and upload the final build to prod server.
There are lots of possible solutions. I can suggest using a task runner(gulp) which will copy these static files to a public directory like dist/assets.
Install gulp on your machine
npm install --save-dev gulp
Create a gulpfile.js file in your root directory with following code.
var gulp = require('gulp');
gulp.task('default', function () {
gulp.src('/node_modules/normalize.css')
.pipe(gulp.dest('./dist/assets'));
});
Run gulp
gulp
Update your index.html as below
<link rel="stylesheet" href="/dist/assets/normalize.css">
Please go through the documentation of Gulp for more information
You can also try Grunt or Webpack
You could use Webpack for bundling, which would copy css resources to the dist and replace references to it. It doesn't support html files as entry points though, so you'd need to work around that by probably using html-webpack-plugin.
anyway, as was mentioned by others - server decisions are weird.
i generated the scaffold of a famo.us project with Yeoman (yo famous)
i set up i small working project
i tried to launch it with 'grunt serve' command
it all works but no image is loaded because the folder content/images is not loaded
how can i include it?
thanks
I'm Myles the author of the Famous-Generator. The images in '/content/images/' should be able to be loaded as an absolute or relative path... although I have just updated the generated 'main.js' to use an absolute path for the sake of being explicit.
Remember that when you famous code is run it will be running inside of index.html, and therefore have the same "relative path" for included assets. As well, since you are serving via a development server, you are able to reference anything with absolute paths relative to the root directory of the project.
You should not have to touch requireConfig at all to be honest. It is only used to add vendor code installed in 'lib' to your path within require so you can reference modules by name rather than path. 'underscore' rather than '../lib/underscore'. This becomes nice as you begin to nest folders and don't want to have to manage relative paths. This also makes your code a lot more portable!
A nice sidebar, you should install all vendor code with 'bower install --save $LIB_NAME'. This will save the library / version to your bower.json and inject the path for the module into you requireConfig. Basically you can bower install anything and just start requiring!
yo famous is working just fine!
it was my mistake to try to set relative paths inside requireConfig including images: that is not working but i don't know if it is supposed to!
you have to use relative paths for every image and everything will be ok!
Using the webapp generator, I have created a yeoman project. I have some html templates in the app folder in a 'templates' directory. I am able to get these files revved when running grunt build; however, I am not able to update to references to the html templates in the js files in the 'scripts' directory. Is it possible to use the usemin task on js files or is it a bad idea to rev html templates used by js files in the first place?
Before building:
-root
-app
index.html
-templates
template1.html
-scripts
script1.js (used template1.html)
After building:
-root
index.html
-templates
43643.template1.html
-scripts
345345.script1.js (does not update ref to template1.html)
My gruntfile is pretty basic, just added directories to the rev task. Any suggestions would be appreciated. Thanks in advance.
you can use patterns like in the following question: Using grunt-usemin with dynamically generated image paths
I used this to search revisoned js files into other js files.
When you do this, bear in mind that you have to write all relative path in the, in my case I had to change something like:
...
var file = basePath + 'filename.js';
...
to
...
var file = 'base/path/filename.js';
...
Cheers,