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

Vite Plugin migration path, with some findings #7889

Closed
wants to merge 1 commit into from

Conversation

Plopix
Copy link

@Plopix Plopix commented Nov 3, 2023

Just a little more doc on the migration path.

The ENV vars issue was a struggle (especially if you don't know Vite)
You may also want to look here: https://github.com/withastro/astro/tree/main/packages/astro/src/vite-plugin-env

Also, but that is probably a bug, I had to npx remix reveal otherwise I had this error:

....node_modules...dev/dist/config/defaults/entry.server.node.tsx" outside of root directory

Most likely because I have PNPM workspaces and the node_module is indeed outside. => but that should work

I hope it helps

Copy link

changeset-bot bot commented Nov 3, 2023

⚠️ No Changeset found

Latest commit: aeb53fd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Nov 3, 2023

Hi @Plopix,

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 hello@remix.run.

Thanks!

- The Remix team

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Nov 3, 2023

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

];
```

now you can just do this:
Copy link
Member

Choose a reason for hiding this comment

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

I strongly advise against recommending this. https://www.epicweb.dev/tips/do-not-bundle-all-your-css

Copy link
Author

Choose a reason for hiding this comment

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

I can remove that I was recommended to add it.... so you think that's better to add the ?inline ?

Copy link
Author

@Plopix Plopix Nov 7, 2023

Choose a reason for hiding this comment

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

declare module '*.css' {
  /**
   * @deprecated Use `import style from './style.css?inline'` instead.
   */
  const css: string
  export default css
}

Copy link
Member

Choose a reason for hiding this comment

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

I just mean it's better to actually import the stylesheet and include it itself in most cases.

Copy link
Author

Choose a reason for hiding this comment

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

I understand, it is just that without doing anything, developer will have to understand the change to be made.
Either do the thing you don't recommend or add the ?inline which by itself seemed weird to me too.
So we have to make a decision, or mention both in the migration path I guess.
Let me know!

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why any change needs to be made though. With vite can you not import the href anymore? That sounds wrong (and bad). It would probably be best to get an actual Remix maintainer involved to make a decision here...

Copy link
Author

Choose a reason for hiding this comment

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

of course that's just a sharing feedback here. I am no one to take a decision but yet, indeed it displays a big warning if you don't do anything:

Screenshot 2023-11-08 at 12 26 27 PM

Screenshot 2023-11-08 at 12 27 13 PM

So all I am saying is (and the only goal of that PR): helping developer in the migration paths :)

Which ever is the decision, I will update the PR

Thank @kentcdodds to spot that, it's indeed very important to point people in the good direction!

Copy link
Member

Choose a reason for hiding this comment

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

In theory Vite can support importing the href of a CSS file, but Vite currently has an issue where CSS files imported with the ?url query string don't go through the CSS transformation pipeline. This means tools like PostCSS/Tailwind won't apply to your CSS. We have an issue tracking it from a Remix perspective here: #7786.

In addition to this issue, it's also worth considering that we're trying to pick our battles a bit more when it comes to bundling so that we're better positioned to leverage tools like Vite. As a result, we're targeting CSS side-effect imports as the primary way of managing CSS since this lines up with Vite: https://vitejs.dev/guide/features.html#css.

};
```

#### CSS Import
Copy link
Member

Choose a reason for hiding this comment

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

This is already covered in the "Fix up CSS imports" section.

import { defineConfig, loadEnv } from "vite";

export default ({ mode }: { mode: string }) => {
const env = loadEnv(mode, process.cwd(), "");
Copy link
Member

Choose a reason for hiding this comment

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

This has been fixed in #7958 and will be out in the next release.

@markdalgleish
Copy link
Member

markdalgleish commented Nov 13, 2023

Thanks for the feedback and the PR!

The issues you've raised have all been addressed so this update shouldn't be necessary anymore. If you'd like to confirm, you can try the latest nightly release. If there are any problems, feel free to open a separate issue.

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.

4 participants