Browse Source

编译选项

e 1 year ago
parent
commit
1c4ac6e99f

BIN
JS初级/DOM/JS初级 - 快捷方式.lnk


+ 11 - 0
ts/3.编译选项/dist/a.js

@@ -0,0 +1,11 @@
+console.log("aaa12");
+let a = '1122222';
+console.log(a);
+var obj = {
+    name: "孙悟空"
+};
+function fn1() {
+    console.log(this, 'this');
+    return this.name;
+}
+console.log(fn1.call(obj));

+ 2 - 0
ts/3.编译选项/dist/hello.js

@@ -0,0 +1,2 @@
+let a = 11;
+a = '11';

+ 6 - 0
ts/3.编译选项/dist/m.js

@@ -0,0 +1,6 @@
+export const mm = '妹妹';
+function fn1(x, y) {
+    console.log(this, 'this');
+    return x + y;
+}
+fn1(2, '43');

+ 11 - 0
ts/3.编译选项/index.html

@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script type="module" src="./dist/a.js"></script>
+</body>
+</html>

+ 6 - 0
ts/3.编译选项/src/a.js

@@ -0,0 +1,6 @@
+import { mm } from './m.js';
+console.log("aaa12");
+let a = '11';
+console.log(a);
+console.log(mm, 'mm');
+// do

+ 18 - 0
ts/3.编译选项/src/a.ts

@@ -0,0 +1,18 @@
+// import { mm } from './m.js';
+console.log("aaa12");
+// 哈哈哈哈
+let a  = '1122222';
+// a = true;
+console.log(a);
+// console.log(mm,'mm')
+
+// do
+var obj = {
+    name:"孙悟空"
+}
+function fn1() {
+    console.log(this,'this')
+    // return x+y;
+    return this.name;
+}
+console.log(fn1.call(obj))

+ 2 - 0
ts/3.编译选项/src/hello.js

@@ -0,0 +1,2 @@
+let a = 11;
+a = '11'

+ 1 - 0
ts/3.编译选项/src/m.js

@@ -0,0 +1 @@
+export const mm = '妹妹';

+ 6 - 0
ts/3.编译选项/src/m.ts

@@ -0,0 +1,6 @@
+export const mm = '妹妹';
+function fn1(x:any,y:string) {
+    console.log(this,'this')
+    return x+y;
+}
+fn1(2,'43');

+ 51 - 0
ts/3.编译选项/tsconfig.json

@@ -0,0 +1,51 @@
+{
+    // 编译全部ts文件 tsc
+    // 监听编译 tsc -w
+    // include 匹配文件入口 
+    // ./ ../
+    // 任意文件目录 **
+    // 任意文件 * 
+    "include": [
+        "./src/**/*"
+    ],
+    // exclude 排除文件入口
+    // "exclude": [
+    //     "./src/**/*"
+    // ],
+    // extends 继承
+    // files 文件,
+    // compilerOptions 编译选项
+    "compilerOptions": {
+        // 解决target报错
+        "moduleResolution": "Node",
+        // target规定ts编译成那个js版本: 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'esnext'
+        "target": "ES6",
+        // 模块 module 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'es2022', 'esnext', 'node16', 'nodenext', 'preserve'
+        "module": "ES2015",
+        // lib 用于规定使用那个库
+        "lib": ["dom"],
+        // outDir 规定将编译后的文件具体放在哪个位置
+        "outDir": "./dist",
+        // outFile 将编译后的所有文件放在一个文件下
+        // "outFile": "./dist/app.js",
+        // 是否对js文件进行编译
+        "allowJs": true,
+        // checkJs 检查js文件是否符合编译规范
+        // "checkJs": false,
+        //  removeComments 是否移除注释 默认false
+        "removeComments": true,
+        // noEmitOnError 规定错误是否允许编译
+        // "noEmitOnError": true,
+        // noEmit 规定文件是否被编译
+        // "noEmit": true,
+        // strict 严格检查总开关
+        "strict": false,
+        // alwaysStrict 编译后的文件是否是严格模式
+        // "alwaysStrict": false,
+        // noImplicitAny 不允许数据默认是any类型
+        // "noImplicitAny": false,
+        // noImplicitThis 规定是否允许使用this
+        // "noImplicitThis": false,
+        // "strictNullChecks": true
+    }
+}