Link custom css to components?
I can't seem to find any info on how to link the output css from my project into the fractal components library. Is this done in the config, or?
You’ll want to link to your output CSS file from the preview template(s) used to preview your components. See: http://fractal.build/guide/components/preview-layouts
So, I did this in fractal.js: fractal.web.set('static.path', __dirname + '/assets'); // my css is in assets/css/modules.min.css
And then in _preview.hbs i did: href="{{ path '/css/modules.min.css' }}" // I expect that the above would prefix this path
But the component stays unstyled, what am I missing?
I keep a single .scss file per module. Is there anyway I can just use that in some way (I do not build it individually in my build proces, but rather concatenate them into one file), would be nice if fractal could somehow make use of if in preview the component alone.
Can't seem to find the assets. Could this be a port problem? localhost:3000 is running the fractal stuff, but setting the static path in the config will also point to port 3000, right?
No matter what I try I get this from fractal: 404: No matching route found for /css/modules.min.css ‼︎ 404: No matching route found for /papir/assets/css/modules.min.css ‼︎ 404: No matching route found for /papir
How can I make sure that fractal is looking for asset using port 80 (or whatever port my webserver is running on)?
I had to put the full path to make it work: http://localhost/papir/assets/admin/css/modules.min.css ... hmm, something is not right here ...
Having to build css specific for preview seems like a LOT of extra work ...
@blaasvaer - Fractal intentionally doesn't provide any build/concat/processing tasks for assets. The intention is that you integrate whatever build tool/process that you are comfortable with, rather than having one enforced on you by the system. It's clear however that some people don't want to configure a separate build tool however, so in the future there may well be a pre-configured Gulp file or similar available as an optional extra.
However, regarding your issue - setting fractal.web.set('static.path', __dirname + '/assets'); in your fractal.js file should indeed mean that assets within that directory are served on the same port as the UI (by default port 3000).
I notice that when linking to the 'full path' you have an admin section in the path. That would suggest that you need to have that when linking to it from your preview layout too, i.e:
href="{{ path '/admin/css/modules.min.css' }}"
The static files option just serves files directly from the specified directory, so any folder structure within there needs to be appropriately replicated in the URL structure.
Does that solve the issue?
If I have this in my fractal.js file:
fractal.web.set('static.path', __dirname + 'http://localhost/papir/assets');
or
fractal.web.set('static.path', __dirname + 'http://localhost:80/papir/assets'); // forcing port
and this in the _preview.hsb:
href="{{ path '/admin/modules/pages/pages.min.css' }}"
I get nothing.
I have to have the full path in the _preview.hbs, as I implement this on the actual site, which runs on the default port 80. I have multiple sites running on localhost.
How can you use fractal on multiple separate projects, if it only runs on localhost:3000 instead of localhost:3000/project_name? So I could have individual instances of fractal, one per project.
The static.path option expects a filesystem path, not a URL. So, for example, given the following paths:
- Fractal project root directory:
/Users/foo/projects/papir - Assets directory:
/Users/foo/projects/papir/assets - Css file:
/Users/foo/projects/papir/assets/css/admin/pages.css
Then your config setting would look like:
fractal.web.set('static.path', __dirname + 'assets');
and In your preview template you can access the CSS using:
{{ path '/css/admin/pages.min.css' }}
Ok, this doesn't seem to work for me.
- Fractal project root directory: /Users/nicktoye/Dev/fractal
- Assets directory: /Users/nicktoye/Dev/fractal/assets
- CSS file: /Users/nicktoye/Dev/fractal/assets/css/master.css
i also have this:
fractal.web.set('static.path', __dirname + '/assets');
and this:
I get No matching route found for /css/master.css
my preview.hbs file is here:
/Users/nicktoye/Dev/fractal/src/components/_preview.hbs
What am I missing?
@NickToye in your _preview.hbs are you looking for the CSS file in the CSS folder? For example
<link media="all" rel="stylesheet" href="{{ path '/css/master.css' }}">
@sturobson this is what I have in _preview.hbs
<link media="all" rel="stylesheet" href="{{path '/css/master.css'}}">
Ok, I made the rookie mistake of changing the config in fractal.js rather than my gulpfile.js
@NickToye I'm running into this same issue. can you post what you did in gulpfile.js?
I ran into this issue as well and the solution I found (for development at least) for my case was:
fractal.web.set('static.path', __dirname + '/src/public');
I added in /src/ to the file path because of the directions you follow when creating a new Fractal project, in 'Set up your project structure' has you create a src directory for your project and assets. Note: I am using public instead of assets as some of the comments above mention
I haven't dug deeper into the build process yet and how this will need to be modified to differentiate between the different paths during dev and production.