-
Notifications
You must be signed in to change notification settings - Fork 915
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
cant work with typescript #109
Comments
visit the link to see the project |
Interestingly this is because |
On another look, you may need to set the |
:) thanks |
I too, have tried to setup a TS environment using vue components (I love the idea that it is based on, its small site, and the goal to keep it that way), and while using vue in a plain ts file setup is not a big problem (you can even user nice decorators) , the vue files is a problem as stated above. Further more, the editor support for the vue files is a problem too, as some kind of .d.ts file are missing too. It would be nice if the vue-loader could optionally write a ts (or a d.ts) file in the same path as the vue component. This would fix the above problem, but more importantly it would make better IDE support too, as the tsc now knows the components types too. |
Do you think this problem could be solved by the shorthand ambient module declarations proposal ? |
Hey @yyx990803 can you elaborate a little on the problems? I'm not that familiar with Webpack's internals, but it looks like TypeScript is being fed the |
just to clarify, will ts hot-reload with non-*.vue files? I have managed to get vuex to hot-reload with typescript, but the UI does'nt reload thanks |
You can make vue-loader work with TS, if you put ts code in separate file. myComponent.vue:
myComponent.vue.ts:
You can use both 'ts' and 'awesome-typescript' loaders, just override ts lang option in vue-loader settings. Sample usage here: https://github.com/yegor-sytnyk/contoso-express/ branch alt/vue |
@DanielRosenwasser It seems vue-loader will transform Mind the Here comes the problem. ts-loader do compile file by using |
From what I understand of Webpack, sounds like if vue-loader was able to know to create a |
I found as long as the filename ends with |
If anyone is still interested in using TypeScript in |
@HerringtonDarkholme what changes are there between |
The key change is just a suffix hack. HerringtonDarkholme/vue-ts-loader@d581d46 And all This is the easiest and fastest way I can come up.
|
I see - would it not be better to have |
Oh - I think I see. Loaders don't have control over "generating" files. That file exists on its own and no new distinct files are created (even virtually). Is that correct? |
Exactly. I think a good approach is to support non-ts file by loading extension in tsc. And that should be done by vue-ts-loader so that vue-loader has a uniform interface. |
So Maybe @mhegazy and @jbrantly can weigh in here on any risks of (or previous issues with) that. Also CCing @TheLarkInn. |
Closing, but here's a guide if anyone is trying to get latest |
add ts-loader with options: AppendTsSuffixTo works. @DanielRosenwasser |
@doun How did you do that? Please tell me the details. |
@doun It's my fault. I gone well when I remove { modules: false } options in babel. module: {
rules: [
{
test: /\.js/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
// presets: ['es2015', { modules: false }] <- fail
presets: ['es2015']
}
},
{
test: /\.ts$/,
exclude: /node_modules|vue\/src/,
use: [
{
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/]
}
},
]
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
esModule: true,
}
},
]
} |
Has anyone gotten vue2 + typescript2 working with hot reloading using .vue component files? |
Yeps, it works nicely. I think the trick it that webpack uses websockets, and there are a few scripts out there that mix this in a not always functional way. |
@druppy Yes, I just got it working when I was converting a project over from JavaScript to TypeScript. See my comment on how I fixed this |
Still won't work for me. Using ts-loader v2.0.3.
tsconfig.json:
webpack.conf.js:
Getting this output:
But if i just replace ts-loader with vue-ts-loader and change script attr to
Any ideas? |
Hey all, here's a sample repo of TypeScript working with It currently uses some augmented export default Vue.extend({
// ... component options here ...
}); instead of just export default {
// ... component options here ...
}; You'll also always need an If you use it, try it out with the Vetur VS Code plugin, which can actually give you some of the same experience TypeScript does in vue-loader specific things:
@aromancev maybe your code doesn't work because you're default-exporting the type of Vue, not Vue itself. |
@DanielRosenwasser yes, that was the case. Thanks! |
Any idea how to use babel loader in conjunction with ts-loader, because this wont work:
|
@StevenTheEVILZ why would you need babel if you have TS? |
@DanielRosenwasser I've noticed your example repo is using custom vue / vue-router dependencies, does it still require them? if so do you know when they'll be able to work with the official vue/vue-router packages? |
@blocka because babel allow you to use es6 api features (non-syntax features) such as iterators, generators, async functions, promises, etc. It automatically polyfills it in for you. That's why lots of people use babel with typescript. |
@StevenTheEVILZ babel doesn't automatically pollyfill any run-time behavior for you. |
Something about babel-loader polyfills because I can use iterator. But now I realize that the above actually works, and it's not babel causing the problem, it's typescript. Sorry about that. |
Does this compile the ts in components twice?
|
I'm with @mythz in wondering if there is a way to get this working on the vue master branch. @DmacMcgreg asks a good question, and I'm wondering if there is an answer to it using the existing "production APIs" . @DanielRosenwasser 's todoMCV is cool because it's a working example. I just wish Vue truly had first class support for TypeScript in it's best features, like https://vuejs.org/v2/guide/single-file-components.html . |
structure of the project
webpack.config.js
app.ts
nani.vue
each time I run webpack, it always report this error,
how to solve this problem?
The text was updated successfully, but these errors were encountered: