I am migrating JS files to Typescript and my goal is, to be able to use both JS and Typescript classes in Vue. I know, I can convert Vue scripts into Typescript, but I don't want to do it right now.
The problem arises in a component.vue file:
this.exceptionHandler = app.resolve('ExceptionHandler');
The errror I get in the browser's console is this (compilation is ok):
"TypeError: Cannot call a class as a function"
ExceptionHandler is defined in a TypeScript .ts file.
The question is: Is it possible to first transpile the TS code to JS ES6, then put the code together and then run Babel on everything to compile it to ES5?
I use these options in the TS configuration:
"lib": ["es7", "es6", "es5", "dom"],
"types": ["reflect-metadata"],
"module": "commonjs",
"target": "es6",
And Webpack 4 config:
{
test: /\.ts(x?)$/,
loader: 'babel-loader?presets[]=es2015!ts-loader',
exclude: [
"node_modules",
"vendor",
"app",
"public"
]
},
When I use just ts-loader, the code works well, but the version of the compiled JS code is ES6 and not ES5.
This may be useful to those of you new to Webapack 4. My working webpack config file looks like this:
If you want to use SCSS inside a single file Vue components, then use this: