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
Next.js Support (SWC) #146
Comments
It does not work on Babel either. Right now, I recommend you to generate special functions in another file and let nextjs to import that file. About the swc tranpiler, I will study it, but may consume lots of time ToT |
Inquired to swc creator (@kdy1), and get answered like below:
Therefore, I recommend you again, build However, when |
Hey @samchon, do you think it is possible now to add support in the current state of swc? |
Not possible. Unfortunately, SWC author said he has no plan to support TypeScript type as an open source in his blog. https://www.reddit.com/r/typescript/comments/y7yghy/typescript_type_checker_stc_will_not_be_open/ |
I still don't understand the difference between supporting typescript type, from what I see in this library you implement transformers and looking at swc plugins and playing with AST it seems possible to implement (rewrite) this plugin for rust to add swc support. Or am I confusing these two things? |
Without type system, how can I implement type checker? Not possible only with plugin API, but needs type system, too. |
Sorry to bother but I just want to understand, from what I could understand by searching the swc codebase, today swc has this file typescript.rs which represents the Typescript AST. In addition, swc also parses the AST and returns the type information: And reading some plugins written in rust for swc, like this one, it looks like it's possible to create what typescript-json does. I ran the example in the README and the output of const result2 = ((input, path = "$input") => {
const $join = typescript_json_1.default.equals.join;
const $io = [
(input, path, exceptionable) => "string" === typeof input.name && "number" === typeof input.age && Object.entries(input).every(([key, value]) => {
if (undefined === value)
return true;
if (["name", "age"].some(prop => key === prop))
return true;
return false;
})
];
return null !== input && ("object" === typeof input && null !== input && $io[0](input, path + "", true));
})(person); // -> false, do not allow The library transforms the code and generates this function to validate equality. Edit: After thinking for a few minutes, maybe now I managed to understand the problem, you can implement the library in rust, but you've lost the ability you have now as CLI, from what I see, you can't implement the library in typescript and leave the swc interpret, either you build in rust or you don't. |
I repeat that, not possible. To make validation script, As you're asking me repeatedly, I asked to the SWC author directly and below is the formal answer from him:
|
Now I understand, sorry to bother you and thanks for your time and patience, I hope one day the author decides to implement it, it would be great to have this kind of library implemented in such a fast compiler. |
Will support through #509 |
FYI swc-project/swc#657 (comment) |
I was able to run typia in nextjs via ts-loader, it is not ideal but at least something:
Here is stackblitz |
@aspirisen Could you elaborate on how your example plays along with Next? I am not super familiar with webpack, but I guess this will "run?" .typia.ts files with the ts-loader. But how does that play along with Next's bundling etc, and what code goes on the server side and on the client side? Does Next.js take the output of this rule without problems as if it were done by Next's own setup, or is there some drawbacks? |
@petertflem except that you have to use separate file for typia code there should be no other disadvantages |
@aspirisen Would it matter much if it compiled other code? I don't really plan to, other than for types and interfaces, but just out of interest. It wouldn't use SWC probably, but other than that? |
@petertflem you can transpile other code via ts-loader, but it is much slower than SWC |
@aspirisen Thanks for the reply! 🙂 |
Can you show how ? If we use |
https://typia.io/docs/setup/#webpack This be helpful? |
Feature Request
A description of the problem you're trying to solve.
Actually SWC doesn't works with Next.js, since the project moved from Babel to SWC. Would be great to support this popular framework.
The text was updated successfully, but these errors were encountered: