-
Notifications
You must be signed in to change notification settings - Fork 486
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 builtin:swc-loader with custom swc options #3067
Comments
we may need a option to disable default transformation of javascript | typescript module, since it will cause the module is transformed by swc twice once people use swc-loader, but the default transformation behavior is friendly to user than manually configure loader especially for new user. {
presets: 'default' | 'transform' // default means don't do any transformation by default and 'transform' means transform ts and js using swc by default
} @TheLarkInn @alexander-akait what's the plan of the |
@hardfist we are still considering this concept (and I don't think preset will sove this problem fully), but there are already two solutions:
I think the valid usage is the first, because you can't neven know which options will be used, but if you have AST, you don't need to parse everything twicy, the same can be used for CSS and HTML, unfortunately, no Here https://github.com/webpack/webpack/blob/main/lib/javascript/JavascriptParser.js#L3897 usage of AST |
we did think of passing ast from swc-loader to rspack to avoid parsing, the tricky part is how to deal with span(or called range), since weback dependency analysis relys on span, but when we use swc-transform the span is polluted so we have to do codegen and parse again to get the right span, so unless swc-transform can ensure span is right after transformation(which I'm not sure is possible) |
Yes, I understand your problem, I completely forgot that this does not happen to save time, although my personal opinion is that this is a bug, at least there should be an option to force it to do. Technically we should have Just side infromation - honestly i don't understand why So do you want to implement |
I think defaultRules is good enough to handle compatibility now, so I don't think introduce |
so this only works for style-loader or you need to do right span calculation in this postcss-loader? |
talking about swc-loader, it opens the possibilities for user to do custom dynamic loaded plugin by swc wasm plugin, which maybe not stable enough, we can also implement wasm-loader(I'm not sure it'a good idea because even the string transformation is easy, but the loader Interface is complex) |
I remember @Boshen's oxc is not compatible with estree too? @Boshen do you think estree compatible ast is a good idea for rust javascript parser?
does babel-loader or swc-loader return ast now? I'm wondering whether babel-loader could get the right span after the transformation or does babel can provides things like untransform to get right span without reparsing |
postcss always caculates spans, so there is no problems with it and yes, we don't use spans here, so I think we don't have such problems at all, we need structures like
If we look at coode - no, but it was design for it, some decent time ago it was not compatible, but at the moment I don't know, we should check it out, but yeah, this feature was originally created for this, it is a pity that it has not gained popularity, because it makes eveything more faster |
even defaultFules is good enough, but it's not that easy to manipulate the defaultRules, user may need to modify defaultRules config directly to remove the internal swc-loader which seems not ideal? @alexander-akait any suggestions? |
@hardfist hm, |
@alexander-akait its easy to add but hard to delete,because users need to know the internal implementation to safely delete swc rule and not breaking other rule |
@hardfist How you want to get AST and ranges from swc-loader? Because if it doesn't return ranges, we still need reparse it...
|
yeah as i said before we just give up reusing ast from swc-loader because of the transform range problems (but we still get performance gain since it's in rust and parallel) |
We can implement something like:
the |
Yeah, we can implement this, it can create a weird case like |
This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
I stumbled upon this use while trying to find a solution to turn on |
it's designed to solve this problem, even it's completed right now but I think it can be used to solve your problem now by using swc-loader before like #3267 (comment), what's the blocker for you? |
EDIT: I realised this is not implemented yet. But this would allow me to configure SWC the way I need it. Thanks for the pointer @hardfist. |
@jraoult it's actually implemented and you can use it now(a example here https://github.com/web-infra-dev/rspack/blob/main/examples/builtin-swc-loader/rspack.config.js#L12), what left is how we disable the default transformation so user's code don't need to transform twice(swc-loader and the default transform) |
Can I extend swc plugins in this way ? like: |
you mean the swc wasm plugin? we plan to support swc wasm plugin in the future, but since wasm plugin is experimental and swc is working on new wasm plugin https://twitter.com/kdy1dev/status/1689859032415358976, it's not on the top priority |
Thank you for your reply ,
to
Then , with webpack rule.resourceQuery(/modules/) open cssmodule。 |
why not just configure rule directly {
module: {
rule: {
test: /\.less$/,
use: [{loader:'css-module', options: {module:true}},'less-loader'],
}
}
} |
The same as the demo above, when we use |
can you provide a repro? |
@thinkey-yang resourceQuery is also supported in Rspack, it seems that you can write like this: rule: {
test: /\.less$/,
oneOf: [
{
resourceQuery: /modules/,
type: 'css/module',
use: [
// xxx
],
},
{
type: 'css',
use: [
// xxx
],
},
],
}, |
@hardfist my project is build by umi , you can get more info form : https://github.com/umijs/swc-plugin-auto-css-modules and https://github.com/umijs/umi/blob/3.x/packages/bundler-webpack/src/getConfig/css.ts. |
to be honest this is a bad design of umi, we have no plan to support this bad design, we suggest you configure css module by module.rules other than auto detect in import style in module. |
Closed as it has been supported. Let's move the further questions to another issue or here: #3067 |
What problem does this feature solve?
users need more and more swc custom options now (see #3054) , and it's not ideal to put more and more swc options to builtins which will bloat builtins, so it would be better to put all these custom swc options to loader, once we support builtin-swc-loader, we may deprecate type: 'ts' and the default transformation of javascript module in the future, which makes rspack more compatible with webpack
What does the proposed API of configuration look like?
The text was updated successfully, but these errors were encountered: