-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specify target components to Builder #169
Comments
@Risker woah that is a crazy long build time! How many components do you have in there? I've never had build times anywhere near that long, although I am well aware that the current parse/build system is in serious need of some performance improvements. Until then... there is no way to only 'build' parts of the UI itself. But if you don't need the UI and just want a rendered component for prototyping then you can certainly use the API to either write a Fractal custom command or a Gulp task or similar to render one or more components and save them to disk. For example, if you put the following into your const fs = require('fs');
const path = require('path');
function renderComponent(args, done){
const app = this.fractal;
const target = app.components.find(args.component);
if (target) {
app.components.render(target, null, null, {
preview: args.options.layout
}).then(function(html){
const filePath = path.join('./', args.options.output || '', `${target.handle}.html`);
fs.writeFile(filePath, html, function(err){
if (err) {
app.cli.console.error(`Error rendering ${args.component} - ${err.message}`);
} else {
app.cli.console.success(`Component ${args.component} rendered to ${filePath}`);
}
done();
});
});
} else {
app.cli.console.error(`Component ${args.component} not found`);
}
};
fractal.cli.command('render <component>', renderComponent, {
description: 'Render a component',
options: [
['-l, --layout', 'Render the component within it\'s preview layout.'],
['-o, --output <output-dir>', 'The directory to render the component into, relative to the CWD.'],
]
}); You could then use the command Would something like that work for you? |
@Risker and If you want to run through all (or some of) your components and renderer them without the web UI you may also want to check out this issue for some ideas: #140 (comment) |
@allmarkedup thanks for looking into this! Starting a build tells me it's trying to export 3164 items. Is that a lot? :) (we treat full page prototypes as components as well, and we got a lot of different page templates) Our main goal with this idea/request would still require the web UI. I'll try to explain this more: rather often somebody on our team is asked to build a prototype page based on our pattern library. When it comes to handing off that prototype to another team to implement, we currently have the following options:
So some kind of filtering system for the builder would come in handy, based on (an array of) component handles. Or even tags! Thinking "build a pattern library of components and dependencies that have "registration-flow" tag attached"... |
@Risker Ok I understand a bit better now, but unfortunately that is not something that is supported right now. A filtering system would be handy but Fractal's dependency tracking is not super-robust at the moment so would need to be improved before something like this could be implemented. I think possibly the best thing I can do for you in the near future is to improve the speed of the build process which I'll hopefully get to look at soon! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hey @allmarkedup, I have a follow up question regarding your code example: #169 (comment) In my project, for a full build, I'm setting a static path like in the documentation: https://fractal.build/guide/web/configuration-reference.html#static-path, so that in components this path:
when doing a build, becomes this:
However, I can't get this behaviour working when using the |
@thomasaull you need to specify env.request.path to the render method:
|
@mihkeleidast Appreciate your help and it seems like this is the bit I was missing. One (probably) last question: When I'm doing a full build, the Everything works, when I'm hard coding this string in my function like in your example. But there is probably a smarter way to do this. This might be what your |
Yeah we have a static path defined in the component (page) meta and we render all the pages this way. |
@mihkeleidast Thanks for the explanation and for your help! :) |
Hey, I'm running a pretty large pattern library on Fractal, with a total build time approaching 30 minutes. Most of the time, though, I don't really need to build the whole library, but only a single component for a quick prototype demo.
Is it currently possible through the API to specify which components to include in the static build?
The text was updated successfully, but these errors were encountered: