-
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
Regroup non-static files #6285
Regroup non-static files #6285
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Re: clean up static
output on each build. We actually don't want to do that. Maybe that will change in the future but I think that's out of scope for this PR. See discussion in #529, @pieh's comment in particular.
This could be a breaking change for plugins that rely on the current public directory structure. I wonder if this should be enabled via a feature flag so it can get some solid real-world testing?
@@ -221,7 +222,7 @@ export default (pagePath, callback) => { | |||
as="script" | |||
rel={script.rel} | |||
key={script.name} | |||
href={urlJoin(pathPrefix, script.name)} | |||
href={urlJoin(`scripts`, pathPrefix, script.name)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think pathPrefix
should be first here. We'll need to ensure this PR works for sites using path prefixes. More info at https://www.gatsbyjs.org/docs/path-prefix/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can test this locally by setting a pathPrefix
in gatsby-config.js
and running gatsby build --prefix-paths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're correct that the pathPrefix
should be leading. I've updated the locations that had it reversed.
I've also tested it locally.
module.exports = {
pathPrefix: `/blog`
};
Output links become
# For gatsby Links
# Without prefix
/jobs
# With prefix
/blog/jobs
# For file paths
# Without prefix
/scripts/component---src-pages-index-js-35049c33efafbda27bb4.js
# With prefix
/blog/scripts/component---src-pages-index-js-35049c33efafbda27bb4.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@m-allanson, to confirm, when running gatsby serve
locally on a build that has pathPrefix
enabled it shouldn't work? All the assets return 404 because Gatsby is serving the the public
folder without a prefix (/blog
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brotzky yep, that sounds right. Check out the notes here on how to make this work for testing: https://github.com/gatsbyjs/gatsby/tree/master/examples/using-path-prefix
@@ -252,7 +253,7 @@ export default (pagePath, callback) => { | |||
as="style" | |||
rel={style.rel} | |||
key={style.name} | |||
href={urlJoin(pathPrefix, style.name)} | |||
href={urlJoin(`styles`, pathPrefix, style.name)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment about pathPrefix
@@ -291,7 +292,10 @@ export default (pagePath, callback) => { | |||
// Filter out prefetched bundles as adding them as a script tag | |||
// would force high priority fetching. | |||
const bodyScripts = scripts.filter(s => s.rel !== `prefetch`).map(s => { | |||
const scriptPath = `${pathPrefix}${JSON.stringify(s.name).slice(1, -1)}` | |||
const scriptPath = `/scripts${pathPrefix}${JSON.stringify(s.name).slice( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
publicPath: program.prefixPaths | ||
? `${store.getState().config.pathPrefix}/` | ||
: `/`, | ||
? `/scripts${store.getState().config.pathPrefix}/` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pathPrefix
before scripts
publicPath: program.prefixPaths | ||
? `${store.getState().config.pathPrefix}/` | ||
: `/`, | ||
? `/scripts${store.getState().config.pathPrefix}/` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pathPrefix
before scripts
* first attempt at lifecycle sequence docs closes #6197 * address Kyle's review I hope this is right... * address Shannon's comments address Shannon's comments
v2 should import Link directly from gastby
Thanks so much for checking over everything! Will not implement "clean up static output on each build" |
…tyles/script paths.
default: false, | ||
describe: `Build site without uglifying JS bundles (for debugging).`, | ||
}) | ||
.option(`group-files`, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a flag to enable grouping of files.
gatsby build --group-files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a flag? We try to avoid adding config wherever possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KyleAMathews -- my bad!
What's the best way to add a "feature flag" for this? I tried looking through the code but couldn't grasp it right away. Is there a standard way to handle this?
I was trying to address this comment
#6285 (review)
This could be a breaking change for plugins that rely on the current public directory structure. I wonder if this should be enabled via a feature flag so it can get some solid real-world testing?
The flag would be temporary for people to try it out and then enabled by default after some time. After that the config option would be removed. The purpose is to provide a smoother transition with a testing phase before implementing a potential breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, there shouldn't be any plugins which directly operate on outputted css/js so I think this change is pretty safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@m-allanson @pieh @jquense can you think of any reason we shouldn't just make this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
w/o the flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the flags the code would be a lot cleaner. Less config options exposed to users and I can remove ifs, globals, and other logic from this PR. I'm in favour of removing the flag if it only impacts 1-2 plugins.
@@ -86,6 +86,25 @@ module.exports = async ( | |||
return hmrBasePath + hmrSuffix | |||
} | |||
|
|||
function getOutputPaths() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was duplicate code in the webpack output configs, so I moved it into a function that also handles the grouping of files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Deploy preview for using-drupal ready! Built with commit d8a8377 |
Deploy preview for gatsbygram ready! Built with commit d8a8377 |
To extend this, there is the possibility of adding configuration for the naming of the folders instead of hardcoding |
While it’s great to clean it up, it will make it probably harder to implement a feature like #5270, which would be really useful in cases where there are multiple apps hosted at the same domain. |
* First shot at fixing #6295 * basically `section.js` becomes `item.js`—we don't expect every top-level sidebar `yaml` item to be "just" a container for a "section" (or group) of subitems anymore * got rid of the "base directory" setting in `section-list.js` to allow linking to pages not living in the main directory associated with the current sidebar (e.g. `docs` for `doc-links.yaml`) * solving the need of being able to put a link to "Tutorial" in the sidebar of "Docs": https://github.com/gatsbyjs/gatsby/blob/ba55b66e169a16bfb3333658ad804b7ef0d3d197/www/src/data/sidebars/doc-links.yaml#L7-L8 * all links in the sidebar `yaml` files have to be explicit again, e.g. `/docs/` can't be ommitted anymore; that allows the code to be quite a bit simpler * fix false multiple active items on the "Features" page * adjust sidebar item layout a bit * restore `doc-links.yaml` to fit current docs, moved some things for testing * naming is confusing in a couple of places right now * Fix component name * Fix false multiple active items on the "Features" page * move getActiveItem from item.js to body.js and loop over all items in sidebar (as opposed to run getActiveItem on each item individually) * rename `subitems` key to `items` * Styles for miles * reduce letter spacing for sidebar „headlines“/accordion toggle buttons (for both showcase and doc sidebar) * darken sidebar horizontal rules a little * a healthy amount of whitespace fixes for the top-level-item/-section mix * quick bespoke spacing fixes for the tutorial via `ui:tutorial` in `yaml` (fixes #6193) * tutorial-style bullets for subitems everywhere * blockMarginBottom for vertical whitespace * Rename * No hover for section title when accordions are disabled * Rename * Rename * Fix "Features" scrollspy * Restore „Docs“ sidebar
- This line didn't make sense in either English or Spanish. - Added title to links in ES version.
* Pass apiRunner into loader * Define apiRunner for tests * add pageresources into props
Initial tracedSVG support did not include fragments for gatsby-image in 2.0, which uses Fixed and Fluid instead of Resolutions and Sizes. Add support for these new fragments.
@szimek would the ability to name the folder outputs solve your issue? For example, allowing the ability to name the output for all JS and CSS to be I want to respect the minimal configurability approach of Gatsby with this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see much (any?) value in making these directories configurable. Gatsby doesn't care about catering to idiosyncratic aesthetics for outputted code ;-)
It seems reasonable to move js/css into subdirectories. Can see that it'd simplify the experience for people looking around the outputted code + it'd make it easy to write caching rules for js/css.
@@ -55,6 +55,11 @@ const createElement = React.createElement | |||
export default (pagePath, callback) => { | |||
const pathPrefix = `${__PATH_PREFIX__}/` | |||
|
|||
// If enabled, group files in their respective folders otherwise generated | |||
// non-static files will be left in the root of the output directory. | |||
const pathToGroupStyles = __GROUP_FILES__ ? `styles/` : `` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about we use js
/css
instead? Those feel more standard to me + they're shorter (save all the bytes).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KyleAMathews agreed. The original names were based off variables in the code. +1 for saving all the bytes.
* cache page components and static query components states * Track query addition/removal and text changes between builds * fix redux-state (de)serialization after changing components reducer to map
* Made gatsby-plugin-netlify-cms work with gatsby v2 * gatsby-plugin-netlify-cms: use mini-css-extract-plugin
- gatsby@2.0.0-beta.18 - gatsby-plugin-netlify-cms@2.0.0-beta.4 - gatsby-source-contentful@2.0.1-beta.9
graphic design blogpost
…e globs (#6316) * refactor: add criticlal scripts and links to static file globs * fix incorrect type given to staticFileGlobs
- gatsby-plugin-offline@2.0.0-beta.3
@@ -57,8 +57,8 @@ export default (pagePath, callback) => { | |||
|
|||
// If enabled, group files in their respective folders otherwise generated | |||
// non-static files will be left in the root of the output directory. | |||
const pathToGroupStyles = __GROUP_FILES__ ? `styles/` : `` | |||
const pathToGroupScripts = __GROUP_FILES__ ? `scripts/` : `` | |||
const pathToGroupStyles = __GROUP_FILES__ ? `css/` : `` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KyleAMathews renamed to css
and js
Here's the output now
edit: just noticed deploy failed. Going to fix that.
…tyles/script paths.
…/gatsby into topics/regroup-non-static-files
@KyleAMathews @brotzky Here's an example where being able to name output folders is really useful. We have many frontend apps hosted on a single We've got nginx server in front of it all that decides, based on the path, which app should handle given request. At first, we built our blog app only once for all 6 languages and mounted it at We ended up with 6 separate Gatsby apps, each with If I could tell our Gatsby blog app to output all its JS files e.g. to |
@szimek with the perf improvements in v2, wouldn't it be easier to just build that as a single app now? |
@KyleAMathews But it doesn't solve the problem with figuring out which app should handle given request for non-html files. Let's say I do build all languages as a single app. Gatsby will still output all JS files to its With 6 separate builds and using |
There'd only be one app.js for all the pages? I'm not sure I understand. |
Hopefully, this clarifies it a bit more: All our apps are built and deployed independently using Docker and Kubernetes. Even though Gatsby generates unique file names based on the content, I can't put all files from all our apps in a single folder and mount it at We've got nginx proxy in front of all our apps and, based on request path, it proxies the request to a specific app. Thus, I need to be able to write rules for each app based on the path, e.g. proxy all request that match |
@szimek thanks for the detailed explainations! In my opinion, custom name output is out of scope of this PR and could be submitted in a new PR if it's deemed to be valuable feature for the long term of Gatsby. It would be better to discuss the API for such a feature and the implementation in a new issue/PR. Sidenote
|
Could you figure out why there's so many changes? It seems your rebasing went wrong some where. Yes, please remove the flag code. Also agree that your question @szimek isn't very related to this PR so let's move ahead with getting this in. |
Hi,
This is my first attempt at trying to clean up Gatsby's build output. Instead of dumping all the generated files into the root of
public
by default it puts the scripts and styles into their own directories.The naming of
scripts
andstyles
stems from the variables in the repository.Example output based on "hello-world" gatsby v2
To do
Clean upNot requiredstatic/
output on each build