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(builder): optional typescript support #4557
Conversation
It seems that I broke something around the Regex's regarding layouts & pages. I will fix it soon 💪. EDIT : Fixed my mistakes regarding Regex's but now there is a Vue warning causing an error, I need to investigate. |
a77a573
to
e89c26f
Compare
@kevinmarrec Not sure if this is how this works, or if it would be an issue, but I think that this line will evaluate to true for typescript options for maybe do I can try to test if using nuxt from this PR will break anything in my app, but probably wont get to it for a few days. |
@NickBolles Thank for finding this, it will indeed cause an issue, your suggestion or finding a different name for the option are 2 valid solutions. |
Are we ever going to want to pass options to Typescript? We might want it to be an object at some point, for example to pass a location for the tsconfig or something. (which would conflict even more with other packages) Could we simply move it to the build object? it kinda is a build-related option. |
Yeah I think it could be moved to the EDIT : I checked the documentation, the |
d8f64c3
to
55cf1aa
Compare
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.
Generally changes (till know) LGTM. Nice works 😊
Also good decision to move it into build.typescript. I was going to tell that :)) |
@pi0 Thanks for your fast feedback ! I will take into account your code comments soon and I need to fix the unit test :). |
build
config option
build
config optionbuild
option
build
optionbuild
option
Codecov Report
@@ Coverage Diff @@
## dev #4557 +/- ##
==========================================
+ Coverage 91.07% 91.11% +0.03%
==========================================
Files 61 61
Lines 2186 2195 +9
Branches 528 533 +5
==========================================
+ Hits 1991 2000 +9
Misses 177 177
Partials 18 18
Continue to review full report at Codecov.
|
Tests are green 🚥✔ |
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.
You're right @kevinmarrec -- LGTM!
Merging to get this enhancenment sooner with
|
build
option
This is not only a big time saver and very elegant solution, but is also a long overdue nuxt feature. After all, this is what nuxtjs is about, it has even TJS in the name NuxTJS. 😀 I am going to try nuxt hacketnews TS using this way and see what happens. |
@husayt There are issues with Vue SFC's using the Babel approach, i'm not sure you'll be able to make your project work ^^ |
I updated the description of this PR with a warning refering to #4563 |
@kevinmarrec What is wrong with this PR? |
@kevinmarrec
still work with 2.6.x ? |
@vlajos No, there has been multiple refactors/breaking changes since this behavior, you can check https://nuxtjs.org/guide/typescript to understand properly how you enable TypeScript support in your Nuxt project :) |
@kevinmarrec I see. Thanks. I wanted to use it with the nuxtbuilder, but could not really make it working. |
@vlajos Hm yes but partially, cause we don't have Nuxt Builder types defined, cause they are depending on too many things in core which also need their types to be defined, which would mean rewrite Nuxt in TypeScript. If you need further help, join our Discord and I'll try to take some time to give you more guidelines for your migration. |
@kevinmarrec Thank you,but practically I gave it up. I wanted to use it mainly to be able to work with typeorm easier, but it seems that it works without typescript as well. Anyway when it becomes a little more supported I may give it another go. |
Types of changes
⚠ Warning ⚠ (EDIT AFTER MERGE)
➡ Please be aware of #4563 , which will likely make this merged PR outdated. ⬅
Description
What if Typescript Support what just about setting a boolean variable to
true
? 😎Prequel
This PR is highly inspired by #4406 made by @chanlito, so special thanks to him.
His current PR state alters Nuxt packages even for non-TS projects, and will also break projects using their own TypeScript module, that's why I implemented a new way to provide the TS support.
Existing TS projects will be able to either keep their own implementation of TypeScript support OR use this built-in optional one.
I. Usage 👨💻👩💻
II. How it works behind the scenes ? ⚙
When the
typescript
option is set to true, and only if is set true, it alters the following Nuxt internal packages :✏ Config (@nuxt/config)
Accept
.ts(x)
files for plugins and middleware✏ Builder (@nuxt/builder) & Common(@nuxt/common)
Watch & Use
.ts(x)
files to generate routes (layouts & pages)✏ Webpack (@nuxt/webpack)
Resolve
.ts(x)
files through Babel, passing the typescript option value to the Nuxt babel preset✏ Babel (@nuxt/babel-preset-app)
Retrieve the typescript option from the preset options to use the @babel/preset-typescript Babel TypeScript preset.
✏ CLI (@nuxt/cli) [Suggestion not implemented yet]
Warning or Error if
tsconfig.json
not found in the source folder, using thesrcDir
config optionIII. What about the documentation ? 📖
I suggest a Typescript section in the documentation OR a How to use Typescript ? in the FAQ.
I will (or at least propose to) take the lead on it if my proposal is accepted and submit a PR regarding this documentation. This latter will talk about type definitions as well (#4164).
IV. What about a Nuxt TS project example ? 📁
An example highly similar to the one in #4406 will be proposed in a different PR if this proposal is accepted.
V. What about tests ? 🛠
A test fixture and an unit test are linked in the PR.
NOTE : Nuxt TS community is growing, we already have a bunch of developers who will be ready to test this support using
nuxt-edge
if this proposal gets accepted and merged 😇@chanlito @hartmut-co-uk @husayt @ksnyde @NickBolles
Checklist: