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

Support custom Vite build.assetsDir option #8843

Merged
merged 5 commits into from
Feb 25, 2024

Conversation

ericchernuka
Copy link
Contributor

I was in need of having the assets directory in a different location due to a proxy. Leveraging Vite's build#assetsDir, I was able to achieve most of what I needed, but there was a straggler file at build/client/assets/manifest-{hash}.js even though the configuration of the asset was set to a different directory. To ensure this file adheres to the Vite configuration, I've added handling to build the path from the Vite configuration.

Testing Strategy:
I wasn't able to find any test regarding the Vite plugin functionality so I ended up utilizing manual testing using the playground. To recreate this, I leveraged the template.local feature of the scripts/playground directory.

  1. Run the following from the project root npx create-remix@latest ./scripts/playground/template.local --template remix-run/remix/templates/vite-cloudflare
  2. Update package.json references for @remix/* to all reference * to match existing base template
  3. Run yarn build to build fresh version with the changes in this PR
  4. Run yarn playground:new to create a fresh template
  5. Install dependencies for this new playground
  6. Run yarn build
  7. The result should be a build directory with client and server directories. The client directory should be a subdirectory named assets, which includes a manifest-{hash}.js.
  8. Update vite.config.ts to match the following:
export default defineConfig({
  plugins: [remixCloudflareDevProxy(), remix(), tsconfigPaths()],
  build: {
    assetsDir: "assets-remix"
  }
});
  1. From the new playground root, run yarn build. The result should be a build directory with two directories, client and server. Within the client directory, there should no longer be an assets directory containing manifest-{hash}.js, and it should now be part of the assets-remix directory.

Previously the manifest location was set to the hardcoded path of `assets`, but if a user configures their build to change the `assetsDir` from Vite the result was a file that was still left in the assets folder.

To handle the configuration in Vite, this moves the path generation to utilize Vite's value so that the manifest javascript file is colocated with all other client assets.

Signed-off-by: Eric Chernuka <[email protected]>
Copy link

changeset-bot bot commented Feb 21, 2024

🦋 Changeset detected

Latest commit: 6b125cb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
@remix-run/dev Patch
create-remix Patch
remix Patch
@remix-run/architect Patch
@remix-run/cloudflare Patch
@remix-run/cloudflare-pages Patch
@remix-run/cloudflare-workers Patch
@remix-run/css-bundle Patch
@remix-run/deno Patch
@remix-run/eslint-config Patch
@remix-run/express Patch
@remix-run/node Patch
@remix-run/react Patch
@remix-run/serve Patch
@remix-run/server-runtime Patch
@remix-run/testing Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Feb 21, 2024

Hi @ericchernuka,

Welcome, and thank you for contributing to Remix!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at [email protected].

Thanks!

- The Remix team

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Feb 21, 2024

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

@markdalgleish markdalgleish changed the title fix: move manifestPath to use vite's assetsDir Support custom Vite build.assetsDir option Feb 25, 2024
Copy link
Member

@markdalgleish markdalgleish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@markdalgleish markdalgleish merged commit 03c93fe into remix-run:dev Feb 25, 2024
9 checks passed
Copy link
Contributor

🤖 Hello there,

We just published version 2.8.0-pre.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Copy link
Contributor

🤖 Hello there,

We just published version 2.8.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants