-
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
Copying JS Files To Generated Content #3177
Comments
I think using Gatsby's static folder is a great use case for this. You can add files that do not need preprocessing in there and all the files are available in dev and production.
You can reference those files like so:
Also, you can read up on it here: |
@luczaki114 Thanks for the suggestion, but I'd discounted that approach because of the things you lose, namely (as outlined at the link you supplied):
The second is not so important, but the first is a big loss. Copying the files via a plugin allows for this kind of validation, and would also allow a hash to be appended to the file name. I'm wondering if a generic alternative to static files is worth considering - one that:
|
Thinking about this a little more: gatsby-config.js
content/lab/example.md
addMetadataToNode()
createPages()
templates/lab
There is also the option if the path is to an npm module to pull out some metadata from the |
MDX sounds like a great solution for this! Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help! |
Unless I've missed something there is currently no plugin that supports copying JavaScript files across to the the built site so that they can be referenced from the generated pages. If I haven't missed something obvious, I'm wondering if this is worth consideration as a plugin? I'll explain my use-case and hopefully the need will be clear.
I'm working on a personal site that displays a number of small, self contained JS scripts - each one is a visual experiment and effectively renders a visual component which may or may not be interactive. Each one exists as its own npm module and uses rollup to build a self-contained umd module which I will copy into my gatsby project, alongside a markdown file with information about the script and instructions if it is interactive.
My directory structure will look something like this:
Which will be available at the url
example.com/lab/alpha
, where the page will need to load the script from a relative path.Just to be absolutely clear: each js file will already be compiled with its dependencies included. It won't need any preprocessing etc. The template will just need to load the script into a container div.
With a generic
lab.js
template. Everything is easy to set up apart from dealing with the JavaScript file. I figure I can use helmet within the template to add a relative link to the js file, but the question is how to copy the js file fromcontent/lab/alpha
tolab/alpha
? I understand how to do this, but I'm wondering:There is currently
gatsby-remark-copy-linked-files
but that copies files linked to in markdown, and copies everything to a single directory.I guess another option is to inline the content of the js file into the generated page within a script tag.
The text was updated successfully, but these errors were encountered: