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

Minimal TypeScript support option added #797

Open
wants to merge 29 commits into
base: develop
Choose a base branch
from

Conversation

igogrek
Copy link

@igogrek igogrek commented Jul 13, 2017

This PR adds TypeScript language option to webpack template.

This is basically the same idea as in: #781

The main difference is that I've tried to find minimal possible configuration and code changes.
So in this case there's a metalsmith plugin that renames .js files from /src to .ts if typescript option is enabled.
This way there's no need to maintain both .js and .ts sources.
Checked with both TS enabled and disabled.

@nickmessing
Copy link

@igogrek, I think we should wait for vuejs/vue#5887 before even considering adding typescript to webpack template, and even then I don't think this will be a valid option since we try to keep this template minimal and even vuex is not here.

@igogrek
Copy link
Author

igogrek commented Jul 13, 2017

Well that's sad. While I certainly agree on keeping template as minimal as possible - TypeScript is one of the most needed (or at least most discussed) features missing on vue-cli (see vuejs/vue-cli#263)

vuejs/vue#5887 shouldn't break anything but I will double check

@nickmessing
Copy link

@igogrek, I think with all of discussion around TypeScript we can make a dedicated typescript template, @posva, do you think that's a valid option after vuejs/vue#5887 gets merged?

P.S. I really think vuejs/vue#5887 will be a big change for typescript support since it will make it possible to not use vue-class-component. I'm waiting for it for a long time.

@LinusBorg
Copy link
Contributor

@nickmessing makes sense to wait for #5887.

@yalishizhude
Copy link

Hey~you forget unit tests

@igogrek
Copy link
Author

igogrek commented Sep 13, 2017

@yalishizhude
Thanks. Will think how to do it best after vuejs/vue#6391 is merged.

…pt-option

# Conflicts:
#	template/package.json
@igogrek igogrek changed the base branch from master to develop October 9, 2017 10:33
@igogrek
Copy link
Author

igogrek commented Oct 9, 2017

Updated the fork and dependencies versions.

@yalishizhude
I've added unit test TypeScript support. Note that it will need to be changed again as #824 likely will be merged soon.

Waiting for 2.5 for now, to be able to update TypeScript usages properly (definitions are merged already).

@solarhell
Copy link

@igogrek Vue 2.5.0 already released 🍺

@igogrek
Copy link
Author

igogrek commented Oct 16, 2017

@solarhell I've updated PR again to use Vue.extend() now.

Couldn't find any docs for the new intended TypeScript definition usage, but this approach seems best and autocompletion works great.

Tested different combinations with different ESLint settings and everything seem to work now.

"compilerOptions": {
"module": "es2015",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,

Choose a reason for hiding this comment

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

not needed anymore I presume

Copy link
Author

Choose a reason for hiding this comment

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

Yes, removed. Thanks.

@aesfer
Copy link

aesfer commented Oct 25, 2017

For anyone wanting to give this PR a try you can use:

vue init vuejs-templates/webpack#pull/797/head my-project

@skray
Copy link

skray commented Oct 26, 2017

@igogrek did you have plans to convert the included unit test as well? I would find it strange to generate a TS project and to have some of the files still be Javascript.

I bring this up because if you do convert it over, at a minimum you'll need to include the @types/mocha and @types/chai dependencies, and add import {expect} from 'chai' to the Hello.spec.ts file.

@LinusBorg
Copy link
Contributor

More or less, but not really.

  • the main entry point has to be .ts
  • tsconfig.json should be provided
  • typescript dependencies are not installed

Just check out the diff to see what UP did.

BTW once #1218 is merged I will merge this next.

I just wanted to have a flexible testing setup first to test the template with and without typescript in CI.

@prograhammer
Copy link

prograhammer commented Jan 5, 2018

Hi guys,

This PR for fork-ts-checker-weback-plugin will TypeCheck and TSLint the typescript blocks in Vue SFCs. We're hoping to merge it in soon but you can test it out with the built repo: npm install git://github.com/prograhammer/fork-ts-checker-webpack-plugin.git#vue --save-dev.

Also, use the shorter lang="ts" in the script section (I'll update that later). Check out the first post of that PR for complete information.

And for VSCode there is TSLint Vue which works on your lang="ts" script blocks in Vue files. Although you will still need that Vue declaration file sfc.d.ts for .ts files to understand .vue imports.

cc @LinusBorg @yyx990803

@Toilal
Copy link
Contributor

Toilal commented Jan 10, 2018

fork-ts-checker-weback-plugin has been released as 0.3.0 with support for vue SFC files.

@Toilal
Copy link
Contributor

Toilal commented Jan 10, 2018

When TypeScript is chosen, .vue files should not be processed by eslint as it doesn't natively support typescript.

Maybe we could try https://github.com/nzakas/eslint-plugin-typescript ? This could allow to run "eslint --fix" after generating the project.

@LinusBorg LinusBorg modified the milestones: 1.3.0, 1.4.0 Jan 10, 2018
# Conflicts:
#	template/src/App.vue
@igogrek
Copy link
Author

igogrek commented Jan 11, 2018

@Toilal
That could work, but I think that TSLint via fork-ts-checker-weback-plugin would be much better choice since it can do TSLint too.

I would've added this plugin already but most likely there will be more issues with specific cases (like I already had with Jest) and I would rather leave this as is for now.
Or it would be nice if someone could test this out thoroughly.

PS: fixed conflict, CI error looks quite strange and unrelated to the code.

@ffxsam
Copy link

ffxsam commented Jan 11, 2018

@igogrek For what it's worth, feel free to borrow any of my work from this PR: #1238

It adds TSLint support to the template, with the right configuration to have it work out of the box with VSCode. It was a bit tricky, since TSLint's no-unused-variables seems to fight with the tsconfig noUnusedLocals.

@Toilal
Copy link
Contributor

Toilal commented Jan 11, 2018

fork-ts-checker-webpack-plugin is really better, but it involves more changes. You may have a look to http://github.com/Toilal/vue-webpack-template as it's already implemented among other options. (it's a fork and I try merge as often as possible to minimize changes from official)

@igogrek
Copy link
Author

igogrek commented Jan 24, 2018

@LinusBorg
I'm not completely sure how to fix full and full-karma-airbnb builds as they seem to miss some scripts, namely lint unit and e2e (I assume not in package.json).
Just updated from develop and it doesn't look like it's caused by my code..

@@ -3,7 +3,7 @@
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
Copy link

Choose a reason for hiding this comment

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

Should change the file name to main.ts?

Copy link
Author

Choose a reason for hiding this comment

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

It is changed via metalsmith - that was the basic idea of the PR.
See my initial comment and meta.js

@ThePlastic
Copy link

ThePlastic commented Feb 5, 2018

I wasn't able to try this pull anymore... I got a lot of error and it doesn't ask for any option (i mean, typescript, unit test, linter, e2e...)

@igogrek
Copy link
Author

igogrek commented Feb 5, 2018

@ThePlastic
Pretty sure this is not related to the PR, but with the local environment - most likely global Vue CLI version was updated (3.0?).

@ThePlastic
Copy link

@igogrek I'm sure it is.
I've also updated my vue CLI but got the same errors. So this pull is no longer usable until merge?

@igogrek
Copy link
Author

igogrek commented Feb 5, 2018

@ThePlastic
If you downgrade your CLI back to the version 2 it should work.

@mikob
Copy link

mikob commented May 14, 2018

Thanks for your work on this! Unfortunately, I wasn't able to get it to work either, I've tried vue-cli@2.8.1, 2.9.3 and the current 3 version. Errors look like this:

Error when evaluating filter condition: isNotTest
Error when evaluating filter condition: isNotTest
...

@igogrek
Copy link
Author

igogrek commented May 14, 2018

@mikob
This will not work with version 3 - try using default TS plugin for it.

I will try to update from fresh develop soon to get unit tests fixed but for now I don't have time.

@Patskimoto
Copy link

Just wondering what's the current status on this being merged into master? I am beginning a new project that will eventually be significant in size, I love all the features this package includes and would really like to use TypeScript within the project.

@ffxsam
Copy link

ffxsam commented Jun 28, 2018

@Patskimoto Why wouldn't you just use the latest vue-cli which has built-in TypeScript support?

@Patskimoto
Copy link

@ffxsam I have since done just that - thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.