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: css support #240

Merged
merged 18 commits into from
Dec 14, 2023
Merged

feat: css support #240

merged 18 commits into from
Dec 14, 2023

Conversation

Aslemammad
Copy link
Contributor

Follow up #171

Copy link

vercel bot commented Dec 9, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
waku ✅ Ready (Inspect) Visit Preview Dec 14, 2023 1:09am

Copy link

codesandbox-ci bot commented Dec 9, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 7a3fdcb:

Sandbox Source
Vanilla Typescript Configuration
React Configuration
React TypeScript Configuration

Copy link
Owner

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

wow, this look like a great work. i'll try it later.

Comment on lines 7 to 9
createServer as viteCreateServer,
resolveConfig as resolveViteConfig,
mergeConfig as mergeViteConfig,
Copy link
Owner

Choose a reason for hiding this comment

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

Let's make our naming convention consistent.
Do you prefer resolveViteConfig to viteResolveConfig?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The first one is better I guess.

Copy link
Owner

Choose a reason for hiding this comment

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

Fine then. We should change everything. If it's small, it can be done in this PR.

Copy link
Owner

Choose a reason for hiding this comment

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

Please check all import { doSomethign as doViteSomething} from 'vite' throughout the code base. My previous code did viteDoSomething.

Comment on lines 4 to 18
import { createHotContext as __vite__createHotContext } from "/@vite/client"
import.meta.hot = __vite__createHotContext(import.meta.url);

if (import.meta.hot && !globalThis.__WAKU_HMR_CONFIGURED__) {
globalThis.__WAKU_HMR_CONFIGURED__ = true;

import.meta.hot.on('hot-import', (data) => import(/* @vite-ignore */ data));

import.meta.hot.on('module', (data) => {
const code = data.code
const script = document.createElement('script')
script.type = 'module'
script.text = code
document.head.appendChild(script)
});
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

code format inconstant. semi

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're correct, I'll fix it after Daishi reviews the code. Thank you.

Copy link
Owner

Choose a reason for hiding this comment

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

please fix it.

@dai-shi
Copy link
Owner

dai-shi commented Dec 10, 2023

When I run npm run examples:dev:12_css, there's a warning on the server console:

The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.

and, a warning on the bowser console:

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.

Are these expected?

Copy link
Owner

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

Sorry for some questions due to my limited understanding of Vite.

packages/waku/src/lib/plugins/vite-plugin-rsc-delegate.ts Outdated Show resolved Hide resolved
Comment on lines 49 to 57
const resolvedViteConfig = await resolveViteConfig({}, 'serve');
const mergedViteConfig = await mergeViteConfig(
{
...resolvedViteConfig,

plugins: resolvedViteConfig.plugins.filter(
(plugin) => !plugin.name.startsWith('vite:'),
),
},
Copy link
Owner

Choose a reason for hiding this comment

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

What happens if we don't have this? Why do we need to remove vite: plugins?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

React refresh would fail

@@ -30,6 +31,7 @@ export type MessageReq =
export type MessageRes =
| { type: 'full-reload' }
| { type: 'hot-import'; source: string }
| { type: 'module'; result: TransformResult }
Copy link
Owner

Choose a reason for hiding this comment

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

It's ambiguous, can we call it module-import instead of module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why not, let me try.

});
resolve(worker);
})
.catch((e) => reject(e));
Copy link
Owner

Choose a reason for hiding this comment

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

Please don't remove this.

...resolvedViteConfig,

plugins: resolvedViteConfig.plugins.filter(
(plugin) => !plugin.name.startsWith('vite:'),
Copy link
Owner

Choose a reason for hiding this comment

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

Again, I wonder why we need this and if we need both in two places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's because we don't vite default plugins to be mentioned two times. For instance react refresh would fail because there would two instances of it.

Copy link
Owner

Choose a reason for hiding this comment

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

#240 (comment)

React refresh would fail

I see. I will play with it later. Does it mean there's only one vite server that keep vite plugins? (Can't guess which from the diff, and I don't remember how many they are...)

Please extract this patch/merge logic in a separate file and reuse it. something like packages/waku/src/lib/plugins/patch-react-refresh.ts.

Copy link
Owner

Choose a reason for hiding this comment

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

I don't exactly mean patching plugin. It should be a reusable logic and preferably add some comments for the intention.

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
Copy link
Owner

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

Looking good! Please see comments.

Comment on lines 4 to 18
import { createHotContext as __vite__createHotContext } from "/@vite/client"
import.meta.hot = __vite__createHotContext(import.meta.url);

if (import.meta.hot && !globalThis.__WAKU_HMR_CONFIGURED__) {
globalThis.__WAKU_HMR_CONFIGURED__ = true;

import.meta.hot.on('hot-import', (data) => import(/* @vite-ignore */ data));

import.meta.hot.on('module', (data) => {
const code = data.code
const script = document.createElement('script')
script.type = 'module'
script.text = code
document.head.appendChild(script)
});
Copy link
Owner

Choose a reason for hiding this comment

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

please fix it.

Comment on lines 7 to 9
createServer as viteCreateServer,
resolveConfig as resolveViteConfig,
mergeConfig as mergeViteConfig,
Copy link
Owner

Choose a reason for hiding this comment

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

Please check all import { doSomethign as doViteSomething} from 'vite' throughout the code base. My previous code did viteDoSomething.

...resolvedViteConfig,

plugins: resolvedViteConfig.plugins.filter(
(plugin) => !plugin.name.startsWith('vite:'),
Copy link
Owner

Choose a reason for hiding this comment

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

#240 (comment)

React refresh would fail

I see. I will play with it later. Does it mean there's only one vite server that keep vite plugins? (Can't guess which from the diff, and I don't remember how many they are...)

Please extract this patch/merge logic in a separate file and reuse it. something like packages/waku/src/lib/plugins/patch-react-refresh.ts.

@dai-shi dai-shi linked an issue Dec 13, 2023 that may be closed by this pull request
@dai-shi dai-shi mentioned this pull request Dec 13, 2023
76 tasks
@Aslemammad
Copy link
Contributor Author

I don't see the second warning, but for the first one, to be honest I don't have any idea. Can we tackle it in another PR later?

Copy link
Owner

@dai-shi dai-shi 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 your work!

import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';

export default defineConfig({
root: path.dirname(url.fileURLToPath(import.meta.url)),
Copy link
Owner

Choose a reason for hiding this comment

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

I think we can omit this. (Can be a separate PR, as I might be wrong, and there are other places like this.)

examples/12_css/package.json Outdated Show resolved Hide resolved
packages/waku/src/lib/plugins/vite-plugin-rsc-hmr.ts Outdated Show resolved Hide resolved
mergeConfig as mergeViteConfig,
} from 'vite';

export async function mergeUserViteConfig(config: UserConfig) {
Copy link
Owner

Choose a reason for hiding this comment

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

It would be nice to add a comment about this workaround is required only (?) for hmr. (Can be a separate PR.)

@dai-shi dai-shi merged commit e3aa021 into dai-shi:main Dec 14, 2023
9 checks passed
dai-shi added a commit that referenced this pull request Dec 14, 2023
dai-shi added a commit that referenced this pull request Dec 14, 2023
This was referenced Dec 14, 2023
dai-shi added a commit that referenced this pull request Dec 14, 2023
* Revert "Revert "feat: css support (#240)""

This reverts commit f32f338.

* possible fix

* possible fix

* fix 12_css package.json

---------

Co-authored-by: daishi <daishi@axlight.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

not compatible with @vanilla-extract/css
3 participants