-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Add a gatsby cli api #14366
Comments
All code to do a programmatic The gatsby-cli is just a wrapper around these commands. You can write your own cli or just execute it from nodejs yourself fairly easy. gatsby/packages/gatsby-cli/src/create-cli.js Lines 176 to 200 in a795c10
|
@wardpeet Thank for point me into the right direction. Is there a more simple aproach? Any documenation? |
This is pretty uncommon so we don't really have a guide for it but this is a small example that should get you going. create a node script: (i'll go for custom-gatsby.js) so you can execute it by doing const gatsbyBuild = require('gatsby/dist/commands/build.js');
gatsbyBuild({
directory: process.cwd(),
sitePackageJson: require(path.join(process.cwd(), `package.json`)),
prefixPaths: false,
noUglify: false,
}) |
Awesome. Thank you so much. |
feel free to reach out if you need more info. |
Hi @wardpeet , I've tried to call gatsby as you recommended above. But that will result in the following error. Any idea what is going wrong here? Error: ContentfulAsset.fixed provided incorrect OutputType: 'ContentfulFixed'
at TypeMapper.convertOutputFieldConfig (/var/task/node_modules/graphql-compose/lib/TypeMapper.js:294:15)
at resolveOutputConfigAsThunk (/var/task/node_modules/graphql-compose/lib/utils/configAsThunk.js:19:41)
at ObjectTypeComposer.getFieldConfig (/var/task/node_modules/graphql-compose/lib/ObjectTypeComposer.js:300:58)
at fieldNames.forEach.fieldName (/var/task/node_modules/graphql-compose/lib/utils/toInputObjectType.js:44:19)
at Array.forEach (<anonymous>)
at toInputObjectType (/var/task/node_modules/graphql-compose/lib/utils/toInputObjectType.js:38:14)
at convertInputObjectField (/var/task/node_modules/graphql-compose/lib/utils/toInputObjectType.js:78:19)
at fieldNames.forEach.fieldName (/var/task/node_modules/graphql-compose/lib/utils/toInputObjectType.js:45:23)
at Array.forEach (<anonymous>)
at toInputObjectType (/var/task/node_modules/graphql-compose/lib/utils/toInputObjectType.js:38:14)
at ObjectTypeComposer.getInputTypeComposer (/var/task/node_modules/graphql-compose/lib/ObjectTypeComposer.js:600:84)
at getSortInput (/var/task/node_modules/gatsby/dist/schema/types/sort.js:38:42)
at addResolvers (/var/task/node_modules/gatsby/dist/schema/schema.js:572:23)
at /var/task/node_modules/gatsby/dist/schema/schema.js:196:15
at Generator.next (<anonymous>)
at asyncGeneratorStep (/var/task/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
at _next (/var/task/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)``` |
You don't get this error when running gatsby build from the cli? |
No, from cli this works as expected. |
@wardpeet I'm trying to do something similar, accomplish a build inside of a Docker nodejs image. How can I tell the build step where to find the plugins declared in gatsby-config.js? When using your example of
|
Summary
Integrate running gatsby in a current node application. This would be like some cli-api.
Motivation
Besides the possibility to use
process_child
and spawn a new process which executes gatsby then there might be a few cases where this is either not as easy to achieve or might seem suboptimal.My concrete case is running gatsby in a lambda function. The process of creating a lambda package is creating a zip-file with all required dependencies and upload that to AWS.
The most optimal process here would be to use e.g. webpack or parcel to create a selfcontained bundled application with every dependency (including gatsby) in the bundle. As a side effect this will treeshake gatsby (and its dependencies) and reduce the application size a lot.
The problem here is that bundlers could not include all dependencies for a forked process. Hence the idea to itegrate it via API.
The text was updated successfully, but these errors were encountered: