-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
TypeScript template? #263
Comments
This would be totally awesome. Ideally prepared with SSR from the start. My company wants to move a fairly big & critical Vue2/Vuex2 core app from ES7 to typescript and I currently try to figure out everything necessary, but there doesn't seem to be much information on google. :( AFAIK since the typescript 2.1 release, one can totally remove Babel from the build pipelines, since TS can now compile async/await directly to ES5. ESLint can be substituted with TSLint, Vue2 already has typescript typings included, and so on. I just do not have any expertise in webpack so I just hope for anyone to step in here. |
I tried stitching ts-loader and typescript to a plain webpack project, mimicking https://github.com/AbeHaruhiko/vue-webpack-typescript without avail. Some weird multi app error. |
There you go, @Anonyfox https://herringtondarkholme.github.io/2016/10/03/vue2-ts2/ "import declarations may only appear at top level of a module" |
Based on the link above; https://github.com/italomaia/blog/tree/master/ux |
When the template is ready, then am also willing to switch ES6 to TS. |
Hello, any news on the template? |
Also looking for any news on the template? |
I have created a typescript template for Vue 2.0 - https://github.com/ducksoupdev/vue-webpack-typescript Let me know what you think? |
@ducksoupdev I've been looking for something similar. It works pretty well, but I think there's place for improvements. Any plan on making it better? |
Thanks. Yes definitely, I am new to Vue having mostly worked with Angular. I am learning lots and would like to improve the template. I would welcome any suggestions including PRs 😊 |
@rorisme What improvements do you have in mind? |
@ducksoupdev @tadejstanic I'm also a VueJS newbie. I'm using the template for a few days now. The reloading seems not accurate, and sometimes it reloaded twice. I've already made some changes and hope to be able to send suggestions and PRs in the days coming. Btw, thanks to @ducksoupdev for sharing! |
@rorisme Would be keen on any suggestions or PRs. This is early days and I would like to improve the template going forward. The compilation of both the Typescript and then the webpack bundle would explain the two reload issue. I am aware of it and possible fixes, just not got around to fixing it yet! |
@ducksoupdev I just made some adjustments to a fork of the template available here. Could you check it out and see if it's necessary to make a PR? I have tested scripts like |
@rorisme looks good, definitely worth a PR :) |
Any plans to make this offical into generator? |
I'm using the @ducksoupdev template but would love to see an official one from vue |
Maybe, using flow, we could use most of what TS has that is amazing, without big changes: https://flowtype.org/en/docs/install/ Opinions? |
@italomaia Typescript provides more than typing... async/await, class casing, etc |
@delaneyj do we need all TS has to offer? Actually, what do we need? I would be happy with type casting alone. ps: async/await, can be provided by syntax-async-functions |
@italomaia true, but in larger projects things like interfaces, case classes, generics, enums are so much more than what can be done currently in flow. |
I am the author of agent framework. I created one vue typescript template with fully functional backend written in 100% typescript. vue init agentframework/webstack your-project Source code: https://github.com/agentframework/webstack |
I wrote Toilal/vue-webpack-template, a fork of the official webpack template that works really well with TypeScript (even if you can use it with ES6). Main purpose of the fork is to use standard files for components ( So it has exactly the same features from official template, but it's based on vue-hot-reload-loader and vue-templates-loader instead of vue-loader. Everything from upstream will be merge in the future. You should really try it, feel free to open issues for feedbacks or questions. |
Does anyone know of any solutions with Typescript + single .vue file components + Hot Module Reload? |
@DmacMcgreg Use webpack official template and |
Do you have an example to use? |
I would also be interested in a proper typescript template. Adding I've tried:
And I still get a bucketload of errors, usually along the lines of
Where that file is just a basic
Not to mention a bunch of redeclaration errors and so forth. I've thus far been unable to find any good examples of getting this to work using vue's built-in declarations (most articles I can find use |
@rizqidjamaluddin I had the same issue with a I was eventually able to get my project working with the following changes. webpack.config.jsMake sure your entry is a TypeScript file and not JavaScript. My // webpack.config.js
module.exports = {
entry: './src/app/main.js', // <-- this causes problems
output: {
path: __dirname,
filename: 'build.js'
},
resolve: {
extensions: ['.ts', '.js']
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules|vue\/src/,
loader: 'ts-loader',
options: {
/*
When entry is a .js file the options for this loader is ignored by vue-loader.
`ts-loader` will be loaded without these settings and that's why TypeScript can't
find the .vue files like we expect.
*/
appendTsSuffixTo: [/\.vue$/]
}
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
esModule: true
}
}
]
},
devtool: 'source-map'
} To fix it make sure your entry file is // webpack.config.js
module.exports = {
entry: './src/app/main.ts', // <-- entry must be a .ts file
output: {
path: __dirname,
filename: 'build.js'
},
//...
} references.d.ts and tsconfig.jsonThis fixed the ERROR in /project-dir/src/app/ComponentContent.vue.ts
(15,31): error TS2307: Cannot find module './components/ComponentContent.vue'.
ERROR in ./main.ts
(1,8): error TS1192: Module '"project-dir/node_modules/vue/types/index"' has no default export. ktsn's answer put me on the right track - make sure you have a declaration for the type emitted from // references.d.ts
declare module "*.vue" {
import Vue from 'vue'
export default Vue
} 2017-09-10 correction: previously the above snippet used Using
Also make sure your TypeScript config has // tsconfig.json
{
"exclude": [
"node_modules"
],
"compilerOptions": {
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true, // <-- This is needed (based on settings from `vue-class-component` example tsconfig.json)
"module": "es2015",
"moduleResolution": "node",
"target": "es5"
}
} After that everything compiled and ran as expected. I'd recommend check your (As a note to myself later, this was my solution when running into this issue: vuejs/vue-loader#109) |
prograhammer. Not sure if it's helpful but I posted a fully working starter kit earlier in this thread, that does webpack, typescript within .vue files, vuex, vuerouter, etc. https://github.com/hmexx/vue_typescript_starter_kit |
its sad that takes ages to bring official ts template when comunity is already using it |
Well, the community is already using it, that's great. Someone already seems to maintain it, that's great. That's what open source is about, rifht? I'm thankful that people stepped up to fill a void we lately weren't able to fill with our limited resources. But "sad"? Sorry you feel that way, but I don't think we owe you anything. Please don't waste your time complaining about stuff like this and do something valuable with it instead. Thank you. |
I have several repositories with typescript so as few guys here, i think it would be superb so that you guys select someone who is willing and able to maintain it and put it in cli. So that there is official support and anyone could see - hey those vuers they have bunch of most recent languages and templates prepared, the community is great, with great support. Creating something that everybody is happy about. Thank you that you keep us motivated. |
Here's my suggestion. I think instead of creating a separate webpack-typescript template it's better to add typescript support to the existing webpack template and have the CLI tool to optionally include it. TypeScript can totally replace Babel, but they can also co-exist if that makes things easier for maintaining the template. If possible, externalize all parts of the build scripts that add TS support in a separate file. It only needs to allow |
I maintain a webpack template fork adding TypeScript and vue-class-component here, provided by some additional options to the official webpack template. Having typescript as an option in the official webpack template is definitively the way to go, and would not require that much work. It's possible to use the metalsmith option in |
Hi @Toilal, this is great, but that change is still too big for a merge. I'm not a VueJS moderator, but I think you can do few things if you want it to be considered as pull request:
For now I think the important thing is to get the most minimal TS support accepted into the official webpack template, and we can make it better from there. |
For everybody who needs a TypeScript or a Library template, you should try again https://github.com/Toilal/vue-webpack-template. It's merged with current develop branch of webpack template, and now brings 3 new questions on top of it:
The template currently use dummy Single File Components with src attributes poiting to external For people who tested this fork months ago, It's now really closer to the official webpack template (it use vue-loader). |
if it's possible to get rid of babel when using typescript, that would be a "cleaner" implementation |
@AccessViolator I'm not sure it's a so good idea. Babel is great at providing polyfills and other features, so in many case it's better to make TypeScript target es6, and still use babel on TypeScript output to ensure older browser compatibility. |
Couldn't you just target ES5 in Maybe I'm oversimplifying things, but I've setup a few of my own typescript projects and ended up ditching babel transpilation as I saw no need to keep it assuming all your code is typescript. |
I also feel that whatever implementation is merged should (probably) use the |
@Skwai Do you know if this is easy to add after installing this template? Could I just install |
@dbettin Worked for me as far as I can remember. Also installed |
@yyx990803 is having a TypeScript Template out of scope for the foreseeable future of Vue, or is there something cool about to drop from Vue CLI that will be an official solution for this? Tons of use were enthralled after your 2.5 update blog, but when it came time to build a project we realized the great comfort of having the cli (and a template) to guide us along the way. |
Thank you to the team and integrating typescript template in vue cli v3! |
@ericop it's already supported in 3.0. |
@yyx990803 Awesome, thanks! |
I tried v 3.0 and it gives you a lot of usefull option (first of all you can choose typescript and css preprocessors). Does this eliminate the need to use webpack? And if not, when this template will be available on webpack?? |
@ThePlastic 3.0 is built around webpack, but it is abstracted away to keep it simple for the end-user. But you can configure it if you need to. |
@rigor789 That's the definition of cool |
How to setup a project using typescript template in vue-cli 3.0? I see there is cli-plugin-typescript but how to use it to init a new project? |
@teslor |
Is there any way to change configuration corresponding to |
@rigor789 It's abstracted away, but how would we customize the webpack configuration if we needed to? |
@kronok it's all written in the docs here: https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md 👍 |
Any chance for an official typescript template?
The text was updated successfully, but these errors were encountered: