Skip to content
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

feat(assets): assetsFlatten option #17626

Closed
wants to merge 2 commits into from
Closed

Conversation

karlvr
Copy link

@karlvr karlvr commented Jul 7, 2024

Description

Add an option to stop flattening the assets directory when building. On sites with a lot of static assets, it can be nice to preserve the directory structure that the developer created to manage the files... it helps debugging the bundle as the files are in their expected locations (just with a hashed name).

I found this discussion of this topic #2447, and I think this config option solves this nicely.

I have created a test case for this by duplicating the default test case for assets... I wonder if there's a nicer way to do that than to duplicate all of that code... I removed some of the test cases from it that didn't appear relevant... but there's still a lot. I'm happy to try to improve that with some pointers.

karlvr added 2 commits July 7, 2024 12:41
Note that I had to modify listAssets to support recursive assets
Copy link

stackblitz bot commented Jul 7, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@patak-dev patak-dev added the p2-to-be-discussed Enhancement under consideration (priority) label Jul 15, 2024
@patak-dev
Copy link
Member

I'll add this proposal to the team board for future discussion. About the tests, I think we shouldn't re-run the whole assets playground for this one. Maybe we could add this config to some of the other playgrounds to avoid creating new ones. But we can wait to see what others think about this feature before that. To be honest, we didn't have much requests so far except for the linked discussion but I agree that not having the complete path to be able to use rollupOptions.output.assetsFileNames is a departure from rollup that may be too opinionated.

@patak-dev
Copy link
Member

@karlvr we discussed this PR in today's team meeting and the consensus was that being able to keep the assets structure doesn't justify at this point maintaining an extra config option. We haven't had many requests for this in the past years so it seems there is not enough demand for this extra flexibility. Let's close the PR for now, but thanks for bringing the idea forward.

@corey-cb
Copy link

@patak-dev There is absolutely demand for this

@Celtic-Bytes
Copy link

yes, there is demand for this

@moskaliukua
Copy link

it's possible using originalFilename like this

rollupOptions: {
  input: pages,
  output: {
    assetFileNames: (assetInfo) => {
      if (assetInfo.name?.endsWith('.html')) {
        return assetInfo.originalFileName
      }
      return 'assets/[name].[ext]'
    },
  },
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: build p2-to-be-discussed Enhancement under consideration (priority)
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants