-
-
Notifications
You must be signed in to change notification settings - Fork 433
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
add appendTsxSuffixTo option #581
Conversation
Thanks for this! Could you tell me what the use case for this is? Also please could you fix the tests and provide a new one for the new feature? Thanks! |
Hi, this allow us to use options like this:
So we can use jsx in *.vuex:
|
src/index.ts
Outdated
@@ -27,7 +27,8 @@ function loader(this: interfaces.Webpack, contents: string) { | |||
} | |||
|
|||
const rawFilePath = path.normalize(this.resourcePath); | |||
const filePath = utils.appendTsSuffixIfMatch(options.appendTsSuffixTo, rawFilePath); | |||
let filePath = utils.appendTsSuffixIfMatch(options.appendTsSuffixTo, rawFilePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Come the first uses rawFilePath
and the second uses filePath
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So why this:
let filePath = utils.appendTsSuffixIfMatch(options.appendTsSuffixTo, rawFilePath);
filePath = utils.appendTsxSuffixIfMatch(options.appendTsxSuffixTo, filePath); // shouldn't this be rawFilePath too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only different is when filename is matched by both options.appendTsxSuffixTo and options.appendTsSuffixTo.
In that case, if both part use rawFilePath then .tsx
append will overwrite .ts
, but i think it should become .ts.tsx
so user may know that their regexes has collision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right - thanks for that. Is it likely that people will use appendTsxSuffixTo
and appendTsSuffixTo
together? Or is it an either / or thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They can use it together if they want (declare at a single place and then reuse for example), i can code it more generic but after consider backward-compability i chose this method.
Hi @johnnyreilly Please help me on the failed test of travis-ci, seems to be a nodejs problem? |
I spy green tests - looks like you're getting there! |
I updated documents only to trigger re-test :( the CI's are stupid. |
Yeah - the integration tests are somewhat flaky which is a pain. Way too many false negatives. |
README.md
Outdated
entry: './index.vue', | ||
output: { filename: 'bundle.js' }, | ||
resolve: { | ||
extensions: ['.ts', '.vue'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does '.vuex'
need to be here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes i'm sorry, i committed a new one.
src/utils.ts
Outdated
@@ -88,6 +88,17 @@ export function appendTsSuffixIfMatch(patterns: RegExp[], path: string): string | |||
return path; | |||
} | |||
|
|||
export function appendTsxSuffixIfMatch(patterns: RegExp[], path: string): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having pondered I think it might make for nicer code to combine appendTsSuffixIfMatch
and appendTsxSuffixIfMatch
.
Here's my reasoning:
Wherever appendTsSuffixIfMatch
is called in the code, the output is then passed into the call to appendTsxSuffixIfMatch
. They are never called in isolation and are intended to be used together.
That being the case, I think it might make sense to have an appendTsTsxSuffixIfMatch
method which internally does the appendTsSuffixIfMatch
and appendTsxSuffixIfMatch
operations, feeding the output of the first into the second. This should result in clearer code at the call sites. It may also allow for some genericisation for the underlying methods (whether or not that makes sense I don't know)
Is that okay with you? I'm quite focused on keeping the source of ts-loader as comprehensible as possible to ease contributions by others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just commit.
hi @johnnyreilly all tests passed :) please review and merge, thank you! |
src/index.ts
Outdated
@@ -26,7 +26,8 @@ function loader(this: interfaces.Webpack, contents: string) { | |||
} | |||
|
|||
const rawFilePath = path.normalize(this.resourcePath); | |||
const filePath = utils.appendTsSuffixIfMatch(options.appendTsSuffixTo, rawFilePath); | |||
let filePath = utils.appendSuffixIfMatch(options.appendTsSuffixTo, rawFilePath, '.ts'); | |||
filePath = utils.appendSuffixIfMatch(options.appendTsxSuffixTo, filePath, '.tsx'); | |||
const fileVersion = updateFileInCache(filePath, contents, instance); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be appendSuffixesIfMatch
also please? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry i already code that but forgot to save...
We've all been there 👍 |
The test is failing because of hyper-sensitivity on the part of the comparison test pack. Actually I've fixed that in my latest commit and so if you sync up we should get green tests. Want to give it a go? Instructions here (if you need them): https://help.github.com/articles/syncing-a-fork/ Also @HerringtonDarkholme are you happy with this PR? I ask since you originally added vue support to ts-loader... |
If the only use case is using TSX in vue's SFC. I would not think this is an appropriate approach. The most important issue is vue's tsx ecosystem. See vuejs/vetur#325 (comment) for more detail. |
@vhqtvn could you respond to @HerringtonDarkholme when you get a chance? Thanks. |
@HerringtonDarkholme vuex is just my attempt to use tsx for my project with currently fixed structure setup, the regex can be used like |
Again this is still a choosing problem, one can prefer dedicated tools to solve specified problems but one prefer using generic tools to provide more flexible configurations to the project, as long as it's maintainable by them.
We can, as long as build tool can handle JSX and TS preserve JSX to the building toolchain |
No. The core aim of TS is to type check. Without type checking Vue JSX one cannot say Vue JSX works. For comparison, React's JSX works out of box. Type checking an completion work fine.
Besides advantages, Vue support in ts-loader is pretty much nothing but hack. It requires vue-loader to read all vue file before ts-loader kicks in. So you have constraints to use ts-loader + vue, for example, the entry file must include or recursively include all vue files. It is ideologically atrocious implementation. Yet it enables type checking in Vue, a trade off for significant usage. If plugin is supported, it can be supported ideally. |
I think you mean Without type checking Vue JSX one cannot say Vue TSX works, but tsx here provide solutions for target users that need to use JSX for rendering function and still use TS for the rest, that's too messy to split out logics to standalone tsx file for every component that need it. |
I have demonstrated in length that it is a bogus requirement. You already have render function and template in Vue. If you do need JSX for functional component consider extracting it to external template. If you mix JSX and component template, you'd better refactor for cleaner separation. appendTSXSuffix isn't a good fix. I have said that Vue uses https://blog.golang.org/toward-go2
|
We dont need vuex, it's just my personal way, we can use tsx in vue too as long as the regex match. |
Hi @HerringtonDarkholme and @vhqtvn, First of all, thanks both for your contributions - they're massively valuable and well done for keeping it rational. ❤️ Here's where I am: I don't know Vue (at all) but looking at the docs it seems to have some concept of JSX: https://vuejs.org/v2/guide/render-function.html#JSX. This makes me think that it might be reasonable to allow support for TSX. However, it's not clear to me that React JSX === Vue JSX. I think @HerringtonDarkholme is essentially saying that React JSX !== Vue JSX and so there is no real concept of type checking. Is that right? In that case, is there any value in adding this?
I'm not clear about the whole vuex / lang thing here. (Again, not a Vue user.) Can anyone explain to me what you mean? Speak as you might to a young child. Or a golden retriever. (Couldn't resist the Margin Call hat tip 😉 ) Honestly I've followed only about 30% of the Vue-specific conversation above. Finally, the fact that so many people have chimed in and said they want this makes me think that there's something valuable here. I don't want to ignore that - but I don't want to implement something that's subject to change in 10 minutes time. Is it? Does this feature enable standard Vue usage? Or is it a custom approach that's quite popular? Both are legitimate but if this is custom I wonder if it's appropriate baking it in to ts-loader. If that's the case, would this suggestion resolve the issue in any way:
? I'm totally on the fence right now. |
Yes it enables standard Vue usage because Vue already support JSX - with some limits of cause due to the different between Vue and React. |
I have tried tsx with Vue locally. Actually I think this option brings more problems than it solves.
These two problems will cause more issues to Vue/TypeScript/ts-loader's repos. |
Please explain this more clear, what's the problems you came with?
Ts can be used in vue with standard extension (i.e. https://github.com/vuejs/vue-class-component), Tsx is the better way to code render function within Ts, and it use no more than vuejs/babel-plugin-transform-vue-jsx and ts-loader. |
|
About the |
@vhqtvn Do you ever know how to correctly set up tsconfig? strict should be inside "compilerOptioins" |
Hey @HerringtonDarkholme, I know you feel strongly but let's not move away from courteous disagreement to abuse. ts-loader has got this far powered by ❤️ Let's be good to each other! |
FYI, regarding a TS language service plugin - from https://github.com/Microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin:
So, it wouldn't be possible to have a plugin transform JSX to vue's |
Hi all, i updated the example repo, strict mode wont check JSX typings but all remain functions of ts work, but that's enough for us to write JSX templates within ts code. @HerringtonDarkholme |
Please no invention like |
@octref |
Disclaimer: I'm not a Vue user and I like JSX quite a bit It seems clear to me that you don't like JSX/TSX, which is fine, but I'm having a hard time separating your dislike of the syntax from the logical rationale for not including this PR for those folks who do like it. I think I can distill your arguments into the following (hopefully?):
My reactions would be:
I have a couple of questions though: A. I was looking at https://github.com/Microsoft/TypeScript-Vue-Starter and for the life of me I can't figure out how that configuration works with SFC. In the case of SFC, doesn't
For that matter, might it not be possible to get rid of "appendTsSuffixTo" and have something like:
I'm mostly thinking out loud here, there might be technical issues with actually implementing those since TypeScript is super-eager to load all files off disk. |
@jbrantly |
That's a valid point @octref - if we look to merge this then I'm sure @vhqtvn would be open to changing the docs example to something other than @jbrantly - thanks so much for commenting. As ever, you make some very useful points. What you've said makes sense and brings some useful clarity to the discussion. 👍 Here's my thinking at present:
@HerringtonDarkholme is there anything in my thinking that you disagree with? Anything I've missed? I understand that you're not that keen on |
…pendTsxSuffixTo has been passed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just merge this since @vhqtvn has make tsx to compile.
But warning ahead, maintaining a tool is more than maintaining code. Vue TSX has more hairy complication than a simple appendSuffixTo
can solve.
Thanks for that @HerringtonDarkholme - I appreciate you responding.
I'm sure you're correct. I'm going to take this PR on the grounds that ts-loader won't be doing anymore than appending file suffixes to paths. That's minimal enough and it's agnostic to Vue. That's enough for me to be content. I've made a tweak to ensure that the code doesn't get invoked unless the relevant options are passed - once the CI goes green I'll merge. |
This shipped with ts-loader 2.3.0 - thanks everyone for contributing to the discussion. https://github.com/TypeStrong/ts-loader/releases/tag/v2.3.0 |
Some framework support for VueJSX. I hope some on would have first made feature request to library before modifying build tools. https://github.com/HerringtonDarkholme/av-ts#tsx-example I would, again, argue that framework and language support should precede building tools. Premature releases only ships broken tools and harms user experience. Patience is the virtue. |
That's a fair point and I don't disagree with you. In the end, the simplicity of the addition from a ts-loader perspective and the clear usefulness to a number of people made it a reasonable PR in my view. |
Add support for tsx.