Day29:歪楼无极限(全英文笔记 - III)

虽然今天已经是最後一天,但如果明天系统仍然可以发文的话,会先继续发文,方便之後回顾整理系列文时,能够有更多的篇幅来调整。

但因为下个月又有六角的活动,也许我会想去尝试看看,写一点 open api 的应用,希望年底前能抽出时间来重新翻修这个系列了。

继续补充昨天的笔记,针对 webpack 专案若要支援 TypeScript,该如何设定。

Support TypeScript

I hope this project can support TypeScript, so need install and setting typescript plugin.

npm install typescript ts-loader -D

change index.js -> index.ts and writting somthing.

// index.ts

const target: string = 'Hello TypeScript';
console.log(target);

Webpack default it will look for files with the extension .js file, and the rule of TypeScript requires not to write the extension when importing file.

Between the two will conflict, so need to change the default search extension file in the resolve. The first pick for TypeScript.

In the rules, need to add node_modules to exclude is to avoid affecting. After all, not every plugin uses Typescript.

module.exports = {
  entry: './src/index.ts',
  resolve: {
    extensions: ['.ts', '.js', '.json'],
  },
  module: {
    rules: [
      // ...
      {
        test: /\.ts$/,
        use: ['ts-loader'],
        exclude: /node_modules/,
      },
    ],
  },
};

Finally, mkdir tsconfig.json, this file can write rules about TypeScript.

{
  "compilerOptions": {
    "module": "ES6",
    "target": "ES5"
  }
}

Now, npm run dev, the content of index.ts printed in browser normally.


<<:  day30 Kotlin coroutine 结赛统整

>>:  Golang 学习笔记-- 快速上手/重点整理 - 2 - var, const

初学者跪着学JavaScript Day8 : 资料型别:BigInt

ㄧ日客家话:中文:去哪里 客语:诶 ㄏㄧ 赖 诶 BigInt对数学、金融、科学来说是很重要的,因为...

自动化测试,让你上班拥有一杯咖啡的时间 | Day 7 - 如何写断言

此系列文章会同步发文到个人部落格,有兴趣的读者可以前往观看喔。 在测试脚本加上断言後,当程序码有 ...

[MSSQL维护] SQL 侦测 - 在忙什麽,为什麽这麽慢~~

不乖,就杀了你 KILL SPID KILL 83 Query在忙什麽? if 1=1 SELECT...

【第二天 - Git 泄漏】

Q1. Git 是什麽? Git 是一个分散式版本控管软件,每个开发者手中都会有完整的一份副本,包含...

#18 No-code 之旅 — 读取资料库来实作部落格 ft. Notion SDK

嗨大家~ 像昨天文章里提的,这专案会采用 Notion 来当 CMS (包含资料库),意思是部落格文...