微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Vite 运行 TypeScript 文件原理剖析 All In One

Vite 运行 TypeScript 文件原理剖析 All In One

Vanilla + TypeScript

# create project
$ yarn create vite

# install
$ yarn

# dev
$ yarn dev

ESM

import './style.css'

const app = document.querySelector<HTMLdivelement>('#app')!

app.innerHTML = `
  <h1>Hello Vite!</h1>
  <a href="https://vitejs.dev/guide/features.html" target="_blank">Documentation</a>
`

interface Human {
  name: string;
}

class Person implements Human {
  name: string;
  constructor(name: string) {
    this.name = name;
  }
  getName() {
    console.log('name', this.name);
  }
}

const person:Person = new Person('xgqfrms');

person.getName();
person.name;

Vite 处理后, ts => js ✅

浏览器直接访问 HTTP Server ❌

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "video/mp2t".
Strict MIME type checking is enforced for module scripts per HTML spec.

refs


Flag Counter


©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐