Skip to content
This repository was archived by the owner on Dec 1, 2019. It is now read-only.

Commit 9c1e698

Browse files
committed
init
0 parents  commit 9c1e698

File tree

9 files changed

+4067
-0
lines changed

9 files changed

+4067
-0
lines changed

.babelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
"@babel/preset-typescript",
4+
["@babel/preset-env", { "modules": false }]
5+
]
6+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
./dist
2+
./node_modules

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Typescript Setup
2+
3+
## Webpack
4+
5+
- **Webpack + ts-loader**
6+
- Webpack + babel + @babel/preset-typescript
7+
8+
## Rollup
9+
10+
- Rollup + rollup-plugin-typescript
11+
- Rollup + babel + @babel/preset-typescript
12+
- **Rollup + babel + @babel/preset-typescript2**
13+
14+
15+
UPD: Варианты при которых type-check происходит "на лету" выделены **жирным**. Но у этого есть минус, более медленно компилирование, поэтому если это важно (например для клиентского приложения) то лучше использовать babel.
16+
17+
UPD: [Бабель поджерживает только компиляцию](https://github.com/babel/babel/issues/8301#issuecomment-404108743).

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "example__typescript-setup",
3+
"version": "0.1.0",
4+
"description": "none",
5+
"main": "src/main.ts",
6+
"scripts": {
7+
"type-check": "tsc --noEmit",
8+
"type-check:watch": "npm run type-check -- --watch",
9+
"rollup:watch": "rollup -c -w",
10+
"webpack:watch": "webpack -w"
11+
},
12+
"author": "",
13+
"license": "ISC",
14+
"dependencies": {},
15+
"devDependencies": {
16+
"@babel/core": "^7.1.2",
17+
"@babel/preset-env": "^7.1.0",
18+
"@babel/preset-typescript": "^7.1.0",
19+
"rollup": "^0.66.6",
20+
"rollup-plugin-babel": "^4.0.3",
21+
"rollup-plugin-typescript": "^1.0.0",
22+
"rollup-plugin-typescript2": "^0.17.2",
23+
"ts-loader": "^5.3.0",
24+
"tslib": "^1.9.3",
25+
"typescript": "^3.1.6",
26+
"webpack": "^4.24.0",
27+
"webpack-cli": "^3.1.2"
28+
}
29+
}

rollup.config.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import path from "path";
2+
import babel from "rollup-plugin-babel";
3+
import typescript from "rollup-plugin-typescript";
4+
import typescript2 from "rollup-plugin-typescript2";
5+
6+
// config for using rollup typescript
7+
// export default {
8+
// input: "./main.ts",
9+
10+
// output: [
11+
// {
12+
// file: `test.js`,
13+
// format: "esm"
14+
// }
15+
// ],
16+
17+
// plugins: [typescript()]
18+
// };
19+
20+
// typescript using babel
21+
// export default {
22+
// input: "./main.ts",
23+
24+
// output: [
25+
// {
26+
// file: path.resolve(__dirname, "dist", 'bundle.rollup.js'),
27+
// format: "esm"
28+
// }
29+
// ],
30+
31+
// plugins: [
32+
// babel({
33+
// exclude: "node_modules/**",
34+
// // https://github.com/Tomekmularczyk/react-package-rollup/blob/with-typescript/rollup.config.js
35+
// extensions: [".js", ".ts", ".tsx"]
36+
// })
37+
// ]
38+
// };
39+
40+
// config for using rollup typescript
41+
export default {
42+
input: "./src/main.ts",
43+
44+
output: [
45+
{
46+
file: path.resolve(__dirname, "dist", 'bundle.rollup.js'),
47+
format: "esm"
48+
}
49+
],
50+
51+
plugins: [typescript2()]
52+
};

src/main.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
console.log('HELLO WORLD MAN;');
2+
console.log('You are my father boy;');
3+
4+
// const asd = () => {
5+
// console.log('WARNOTN');
6+
// return '324234'
7+
// }
8+
9+
// asd();
10+
11+
// class Point {
12+
// constructor(public x, public y) {
13+
// console.log('asdas')
14+
// }
15+
// getDistance(p: Point) {
16+
// let dx = p.x - this.x;
17+
// let dy = p.y - this.y;
18+
// return Math.sqrt(dx ** 2 + dy ** 2);
19+
// }
20+
// }
21+
// // ...
22+
23+
// // Reopen the interface.
24+
// interface Point {
25+
// distanceFromOrigin(point: Point): number;
26+
// }
27+
// Point.prototype.distanceFromOrigin = function(point: Point) {
28+
// return this.getDistance({ x: 0, y: 0});
29+
// }
30+
31+
// const p = new Point(1,2);
32+
33+
const test = (): Number => {
34+
let b:Number = 123;
35+
b = 123123;
36+
b = 12325;
37+
console.log(b);
38+
39+
return 123123
40+
}
41+
42+
console.log(test())

tsconfig.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"rootDir": "./src",
4+
"outDir": "./dist",
5+
"target": "esnext",
6+
"allowJs": true,
7+
"moduleResolution": "node",
8+
"allowSyntheticDefaultImports": true,
9+
"noUnusedLocals": true,
10+
"noUnusedParameters": true,
11+
"removeComments": false,
12+
"preserveConstEnums": true,
13+
"skipLibCheck": true,
14+
"typeRoots": ["./node_modules/@types"],
15+
"lib": ["dom", "es2015", "es2016"]
16+
},
17+
"include": [
18+
"src/*"
19+
],
20+
"exclude": [
21+
"node_modules",
22+
]
23+
}

webpack.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const path = require("path");
2+
3+
module.exports = {
4+
target: "node",
5+
mode: "production",
6+
entry: "./src/main.ts",
7+
module: {
8+
rules: [
9+
{
10+
test: /\.ts?$/,
11+
use: "ts-loader",
12+
exclude: /node_modules/
13+
}
14+
]
15+
},
16+
resolve: {
17+
extensions: [".tsx", ".ts", ".js"]
18+
},
19+
output: {
20+
filename: "bundle.webpack.js",
21+
path: path.resolve(__dirname, "dist")
22+
}
23+
};

0 commit comments

Comments
 (0)