Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Building a Backend System with Vue.js, TypeScript, and Vue CLI 3.0

Tech May 15 1

Setting Up a Vue.js Project with TypeScript

Vue.js combined with TypeScript offers a robust development experience. While Vue doesn't have the same level of TypeScript integration as frameworks like Angular, TypeScript's type checking and modern ES6 features provide significant advantages. This guide will walk you through setting up a Vue.js project with TypeScript support.

Installation Requirements

Before starting, ensure you have Node.js installed on your system. You can download it from the official Node.js website.

Installing Vue CLI 3.0

Vue CLI 3.0 can be installed globally using npm or yarn:

# Install Vue CLI using npm
npm install -g @vue/cli

# Or install using yarn
yarn global add @vue/cli

Creating a New Project

You can create a new project in two ways:

# Using the command line
vue create my-project

# Or using the GUI
vue ui

When prompted, you'll see several options:

  1. Previously saved templates
  2. Default preset (recommended for beginners)
  3. Manual configuration

Select "Manually select features" using the arrow keys and spacebar. For this setup, we recommend enabling TypeScript, SASS/SCSS support, ESLint, and other useful features.

Project Structure

After installation, your project will have the following structure:

  • node_modules: Contains project dependencies
  • public: Static assets and the main HTML file
  • src: Main source code directory
    • assets: Static files like images and fonts
    • components: Reusable Vue components
    • views: Page-level components
    • App.vue: Root component
    • main.ts: Application entry point
    • router: Vue Router configuration
    • shims-tsx.d.ts: TypeScript declaration for JSX support
    • shims-vue.d.ts: TypeScript declaration for Vue files
    • store: Vuex state management
  • package.: Project dependencies and scripts

Vue Configuration

Create a vue.config.js file in the project root to customize your build configuration:

// vue.config.js
module.exports = {
  // Base URL for deployment
  baseUrl: "",
  
  // Output directory for production build
  outputDir: "dist",
  
  // Directory for static assets
  assetsDir: "assets",
  
  // Output path for index.html
  indexPath: "index.html",
  
  // Whether to use filename hashing for cache busting
  filenameHashing: true,
  
  // Multi-page app configuration
  pages: undefined,
  
  // Run ESLint during development
  lintOnSave: false,
  
  // Use Vue build with runtime compiler
  runtimeCompiler: false,
  
  // Dependencies to transpile with Babel
  transpileDependencies: [],
  
  // Generate source maps for production
  productionSourceMap: false,
  
  // Cross-origin settings for assets
  crossorigin: undefined,
  
  // Enable Subresource Integrity
  integrity: false,
  
  // Development server configuration
  devServer: {
    proxy: {
      '/api': {
        target: 'http://localhost:3000',
        ws: true,
        changeOrigin: true
      }
    }
  }
}

With these configurations, your Vue.js project with TypeScript is ready for development. You can now start building your backend system with the tools and structure in place.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

SBUS Signal Analysis and Communication Implementation Using STM32 with Fus Remote Controller

Overview In a recent project, I utilized the SBUS protocol with the Fus remote controller to control a vehicle's basic operations, including movement, lights, and mode switching. This article is aimed...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.