Last active
December 17, 2019 07:29
-
-
Save toddlucas/a43b99adb56d12256c7e3fc42792770b to your computer and use it in GitHub Desktop.
Add TypeScript to gulpfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <binding ProjectOpened='default' /> | |
'use strict'; | |
... | |
const tslint = require("gulp-tslint"); | |
const tsify = require("tsify"); | |
const source = require("vinyl-source-stream"); | |
const merge = require('merge-stream'); | |
const browserify = require("browserify"); | |
const paths = { | |
entries: { | |
ts: ["Scripts/main.tsx"] | |
}, | |
vendors: [ | |
"react", | |
"react-dom", | |
"react-redux", | |
"react-router", | |
"react-router-dom", | |
"redux", | |
"redux-thunk" | |
], | |
watch: { | |
ts: [ | |
"Scripts/**/*.ts", | |
"Scripts/**/*.tsx" | |
] | |
}, | |
output: { | |
scripts: "wwwroot/scripts" | |
} | |
}; | |
function lint() { | |
return gulp.src(paths.watch.ts) | |
.pipe(tslint({ | |
formatter: "verbose" | |
})) | |
.pipe(tslint.report()); | |
} | |
function vendor() { | |
const browse = browserify({ | |
debug: true | |
}); | |
paths.vendors.forEach(lib => { | |
browse.require(lib); | |
}); | |
return browse | |
.bundle() | |
.pipe(source("vendor.js")) | |
.pipe(gulp.dest(paths.output.scripts)); | |
} | |
function app() { | |
const browse = browserify({ | |
debug: true, | |
entries: paths.entries.ts | |
}); | |
return browse | |
.plugin(tsify) | |
.external(paths.vendors) | |
.bundle() | |
.pipe(source("app.js")) | |
.pipe(gulp.dest(paths.output.scripts)); | |
// .pipe(browserSync.reload({ stream: true })); | |
} | |
function watch() { | |
gulp.watch(paths.watch.ts, gulp.series(lint, app)); | |
} | |
... | |
const compile = gulp.parallel(gulp.series(lint, app), vendor); | |
exports.compile = compile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "example", | |
"version": "1.0.0", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"description": "", | |
"private": true, | |
"devDependencies": { | |
"@types/react": "^16.9.16", | |
"@types/react-dom": "^16.9.4", | |
"@types/react-redux": "^7.1.5", | |
"@types/react-router-dom": "^5.1.3", | |
"browserify": "^16.5.0", | |
"gulp-tslint": "^8.1.4", | |
"merge-stream": "^2.0.0", | |
"tsify": "^4.0.1", | |
"tslint": "^5.20.1", | |
"tslint-react": "^4.1.0", | |
"typescript": "^3.7.3", | |
"vinyl-source-stream": "^2.0.0" | |
}, | |
"dependencies": { | |
"history": "^4.10.1", | |
"jquery": "^3.4.1", | |
"popper.js": "^1.16.0", | |
"react": "^16.12.0", | |
"react-dom": "^16.12.0", | |
"react-redux": "^7.1.3", | |
"react-router-dom": "^5.1.2", | |
"redux": "^4.0.4", | |
"redux-thunk": "^2.3.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"compilerOptions": { | |
"target": "es6", | |
"jsx": "react", | |
"module": "commonjs", | |
"moduleResolution": "node", | |
"strict": true, | |
"noImplicitAny": true, | |
"strictNullChecks": true, | |
"sourceMap": true | |
}, | |
"exclude": [ | |
"node_modules" | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"extends": ["tslint:latest", "tslint-react"], | |
"rules": { | |
"interface-name": false, | |
"no-console": false, | |
"no-implicit-dependencies": [true,"dev"], | |
"object-literal-sort-keys": false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment