mirror of
https://github.com/gnu4cn/ts-learnings.git
synced 2024-12-26 12:50:31 +08:00
Updated.
This commit is contained in:
parent
a3e7b3692d
commit
866cc29c1d
42
gulpfile.js
42
gulpfile.js
@ -1,28 +1,40 @@
|
||||
// https://stackoverflow.com/questions/40823462/how-to-bundle-typescript-files-for-the-browser-user-gulp-and-tsproject
|
||||
var gulp = require('gulp');
|
||||
var clean = require('gulp-clean');
|
||||
var sourcemaps = require('gulp-sourcemaps');
|
||||
var ts = require('gulp-typescript');
|
||||
|
||||
var tsProject = ts.createProject('tsconfig.json');
|
||||
|
||||
let paths = {
|
||||
pages: ["src/*.html"]
|
||||
};
|
||||
|
||||
gulp.task("copy-html", ()=>{
|
||||
return gulp.src(paths.pages)
|
||||
.pipe(gulp.dest("dist"))
|
||||
gulp.task('clean', () => {
|
||||
return gulp
|
||||
.src([
|
||||
'./dist/'
|
||||
], { read: false, allowEmpty: true })
|
||||
.pipe(clean());
|
||||
});
|
||||
|
||||
gulp.task('tsc', () => {
|
||||
return gulp.src('src/*.ts')
|
||||
.pipe(tsProject())
|
||||
.pipe(gulp.dest('dist'));
|
||||
gulp.task("transpile-ts", () => {
|
||||
var tsProject = ts.createProject('tsconfig.json',{
|
||||
outFile: "app.js"
|
||||
});
|
||||
return tsProject
|
||||
.src()
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(tsProject()).js
|
||||
.pipe(sourcemaps.write('./sourcemaps'))
|
||||
.pipe(gulp.dest('./dist/js'));
|
||||
});
|
||||
|
||||
gulp.task("copy-html", () => {
|
||||
return gulp
|
||||
.src(['./src/*.html'])
|
||||
.pipe(gulp.dest("./dist/"));
|
||||
});
|
||||
|
||||
// 这里 watch 里必须使用 gulp.series
|
||||
gulp.task('watch', () => {
|
||||
gulp.watch('src/*.ts', gulp.series('tsc'));
|
||||
gulp.watch('./src/namespace/*.ts', gulp.series('clean', 'transpile-ts'));
|
||||
});
|
||||
|
||||
|
||||
// 这里必须要有一个 default 任务
|
||||
gulp.task('default', gulp.series('copy-html', 'tsc', 'watch'));
|
||||
gulp.task('default', gulp.series('clean', 'copy-html', 'transpile-ts', 'watch'));
|
||||
|
@ -4,7 +4,7 @@
|
||||
"description": "TypeScript Learning stuffs.",
|
||||
"main": "/dist/main.js",
|
||||
"scripts": {
|
||||
"gulp": "gulp &",
|
||||
"gulp": "gulp",
|
||||
"start": "live-server dist/",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
|
@ -1,4 +1,5 @@
|
||||
/// <reference path="IShape.ts" />
|
||||
|
||||
namespace Drawing {
|
||||
export class Circle implements IShape {
|
||||
public draw(): void {
|
||||
|
8
src/namespace/Circle.ts
Normal file
8
src/namespace/Circle.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/// <reference path="IShape.ts" />
|
||||
namespace Drawing {
|
||||
export class Circle implements IShape {
|
||||
public draw(): void {
|
||||
console.log("Circle is drawn.");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
/// <reference path="IShape.ts" />
|
||||
/// <reference path="Circle.ts" />
|
||||
/// <reference path="Triangle.ts" />
|
||||
/// <reference path="Circle.ts" />
|
||||
|
||||
function drawAllShapes(shape: Drawing.IShape) {
|
||||
shape.draw();
|
@ -1,4 +1,5 @@
|
||||
/// <reference path="IShape.ts" />
|
||||
|
||||
namespace Drawing {
|
||||
export class Triangle implements IShape {
|
||||
public draw(): void{
|
@ -1,11 +1,10 @@
|
||||
{
|
||||
"include": [
|
||||
"src/*.ts"
|
||||
"src/namespace/*.ts"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"noImplicitAny": true,
|
||||
"target": "es2015",
|
||||
"outDir": "dist/",
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"types": [
|
||||
|
Loading…
Reference in New Issue
Block a user