Is it possible to create Vue apps using TypeScript with just Babel?

Is there a way to compile and construct my TypeScript Vue application using only Babel? After extensively utilizing vue-cli-service, I've come to the point where I require a more minimal setup, eliminating the need for webpack or any other similar tools.

This is my .babelrc configuration:

{
    "presets": ["babel-preset-typescript-vue"],
    "plugins": ["@babel/plugin-transform-typescript"]
}

Here are the dependencies listed in my package.json file:

"devDependencies": {
    "@babel/cli": "^7.10.5",
    "@babel/plugin-transform-typescript": "^7.11.0",
    "@babel/preset-env": "^7.11.0",
    "babel-loader": "^8.1.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-typescript-vue": "^1.1.1",
    "typescript": "~3.9.3",
    "vue-template-compiler": "^2.6.11"
},
"dependencies": {
    "vue": "^2.6.12",
    "vue-class-component": "^7.2.3",
    "vue-property-decorator": "^8.4.2",
    "vuex": "^3.5.1"
}

This is my main.ts entry file:

import Vue from 'vue'
import Vuex from 'vuex';
import App from './App.vue'

Vue.config.productionTip = false;
Vue.use(Vuex);
    
new Vue({render: h => h(App)}).$mount('#app');

And here's my App.vue file:

<script lang="ts">
    import {Component, Vue} from 'vue-property-decorator';

    @Component
    class App extends Vue {}

    export default App;
</script>
    
<template>
    <div class="foobar">Babel worked</div>
</template>

This is how I run my build script with Babel:

babel src/main.ts --out-dir build

Answer №1

Regrettably, building with Babel is not possible as it only transpiles languages and does not have the capability to build modules. You will still require a bundler to handle require / import imports. If you want to avoid extensive webpack configurations, you may consider exploring alternatives like Rollup or Parcel

If your intention is to compile typescript and vue typescript, you must install @babel/preset-typescript and @babel/preset-env, and add them to your .babelrc file.

Subsequently, utilize

babel ./src/main.ts --out-dir build --extensions ".ts"
or alternatively use locally installed Babel by executing
./node_modules/.bin/babel ./src/main.ts --out-dir build --extensions ".ts"

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular Service singleton constructor being invoked multiple times

I have been facing an issue with using an app-wide service called UserService to store authenticated user details. The problem is that UserService is being instantiated per route rather than shared across routes. To address this, I decided to create a Core ...

Is there a method to hide the "Add Image" button from the AssetManager in the GrapesJS editor within a Vue component?

Is there a way to remove the Add Image button and its corresponding textbox? Can this be achieved by adjusting the assetManager configuration or through another method? https://i.sstatic.net/dCepd.png Upon initializing, the editor can be configured as fo ...

Tips for determining if a key is present in local storage:

I need to set a key value, but only if it doesn't already exist. In my component1.ts file, I am assigning the key and value in the constructor. However, I want to include a condition that this action should only be taken if the key is not already pre ...

The date appeared correctly in the code, but it did not get stored in the database

please add a photo I am attempting to store the current time in my database using my application. Unfortunately, instead of inserting the correct time, an empty date string is being saved. Can someone help me troubleshoot this issue? ...

Executing JavaScript's addEventListener() function without specifying the event that triggers it

I am currently working on creating a grid of boxes that can be clicked, sending notifications with their respective IDs to the server using SocketIO. <body> <div class="wrapper"> <div id="1" class="box"></div> <div id="2 ...

Color section of a highcharts graph

Is there a way to paint the final section of a highcharts chart similar to what is shown in this image? Chart If painting the last section is not possible, would changing the color of those final datapoints be a feasible alternative? Thank you! ...

Javascript - finding data in a table

I am new to the world of programming and currently learning javascript. I have a table with 754 values in the format 000089/04/18/0601AX. I am looking to create a script that will generate another table containing values with /04/18. Any assistance with ...

Deploying a vue.js application using AWS Lambda functions

Seeking advice on deployment strategies for vue.js + express.js + lambda stack. I am able to deploy express.js to lambda using serverless as the backend. However, I am unsure where I can deploy vue.js as the frontend. I came across an article mentioning th ...

Make sure two elements are siblings in JavaScript / jQuery

Looking at the HTML structure below: <div class="wrap"> <div id="a"></div> <div id="b"></div> </div> A statement is presented as false: ($('#a').parent() == $('#b').parent()); //=> false ...

React destructuring props in a dynamic way

Consider we have a props, an incredibly large object: { "firstname": "John", "lastname": "Doe", "age": 11, "mode: "expert", "website": "stackoverflow.com" "pro ...

Ensure that data is accurately confirmed using an alternative mode within react-hook-form

Currently utilizing react-hook-form with the primary validation mode set to "onChange": const formMethods = useForm({ mode: 'onChange' }) I am looking to modify the mode property for a specific input nested within a Controller, but I am unsure ...

Is it possible to load a jQuery Mobile dialog without the header?

Within my jQuery Mobile website, I have a button in the header that looks like this: <a href="/foo.html" data-rel="dialog" data-icon="grid">Foo</a> The issue arises when JQM requires me to redeclare the head section with all scripts and CSS. ...

Enable contenteditable on table by pressing the tab key

I developed a table entry tool and I would like to be able to input items by pressing the tab key instead of having to manually click on each element. I haven't been able to figure out how to make this function work yet. $('table').on(&apos ...

Is it possible for a cloud function to safely carry out asynchronous tasks after it has fulfilled its promise?

Is it safe for a cloud function to execute async tasks after returning its promise? Take into consideration the following code pattern: exports.deleteUser = functions.auth.user().onDelete(async (user) => { const uid = user.uid; asyncTask1(uid); ...

How to delete an element from a session array using Jquery and Ajax techniques

In my table, each element in an array corresponds to a row. I'm attempting to delete an element when the delete image (with the id deleteRowButton) is clicked. Currently, nothing happens upon clicking the image. However, if I remove the line var index ...

How to make a div slide up using jQuery without obstructing text

A scenario is presented where HTML contains two div elements, one with text and the other hidden initially. The goal is to make the second div slide up from below the first div to create a new background color effect. While sliding up works successfully, ...

The SEMrush API is not displaying an 'Access-Control-Allow-Origin' header on the requested resource

When attempting to utilize the SEMrush API, I made a request using jQuery as shown below: $(document).ready(function() { $.get( 'https://api.semrush.com', { type: 'phrase_this', key: ' ...

Receiving a "Maximum call exceeded" error when using Vue.js router guards for the beforeEach hook

As I work on my Firebase-VueJS app, I am implementing basic security rules with router guards. In my main.js file, I have added the following code to handle permissions based on the user's authentication status. However, I encounter an error 'vue ...

Issues with functionality of Bootstrap 5 popover in responsive JavaScript DataTable

As I work on constructing a web page for my hobby, I am utilizing Bootstrap 5.3.3 and JS DataTables 2.0.5. Within the page, there is a table displaying data about various players. I have implemented a feature where clicking on certain cells triggers a popo ...

jQuery Slider Showing Incorrect Images

My jQuery slider is acting strangely. It hides the first image, shows the second one, but then just repeats the cycle by showing the first image again instead of loading the third one. I'm puzzled about what could be causing this issue in my code. Do ...