Skip to content

Instantly share code, notes, and snippets.

@petersaints
Created February 19, 2018 16:17
Show Gist options
  • Save petersaints/02f75ef8f7069056d7bc48d4a169b0ac to your computer and use it in GitHub Desktop.
Save petersaints/02f75ef8f7069056d7bc48d4a169b0ac to your computer and use it in GitHub Desktop.
TypeScript + Babel configuration using Gulp and/or Webpack (deprecated in favor of a simpler configuration on YanuX Coordinator)
{
"presets": [
"es2015"
],
"plugins": [
"transform-runtime"
]
}
const gulp = require("gulp");
const sourcemaps = require('gulp-sourcemaps');
const webpack = require("webpack-stream");
const ts = require("gulp-typescript");
const tsProject = ts.createProject("tsconfig.json");
const tsBabelConfig = {
declaration: true,
noImplicitAny: true,
sourceMap: true,
target: "es2015",
lib: ["es5", "dom"],
};
const babel = require("gulp-babel");
gulp.task("typescript-definitions", function () {
const tsProject = ts.createProject("tsconfig.json");
return gulp.src("src/**/*.ts")
.pipe(tsProject(tsBabelConfig)).dts
.pipe(gulp.dest("build"));
});
gulp.task("typescript-babel", ["typescript-definitions"], function () {
const tsProject = ts.createProject("tsconfig.json");
return gulp.src("src/**/*.ts")
.pipe(sourcemaps.init())
.pipe(tsProject(tsBabelConfig)).js
.pipe(babel())
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("build"));
});
gulp.task("default", ["typescript-babel"]);
{
"name": "@yanux/coordinator",
"version": "1.0.0",
"description": "YanuX Coordinator",
"main": "build/main.js",
"types": "build/main.d.ts",
"scripts": {
"typescript": "npx tsc",
"webpack": "npx webpack",
"gulp": "gulp",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Pedro Albuquerque Santos <pedro@albuquerques.net> (https://pedro.albuquerques.net)",
"license": "LGPL-3.0",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"dts-bundle": "^0.7.3",
"gulp": "^3.9.1",
"gulp-babel": "^7.0.1",
"gulp-sourcemaps": "^2.6.4",
"gulp-typescript": "^4.0.1",
"source-map-loader": "^0.2.3",
"ts-loader": "^3.5.0",
"typescript": "^2.7.2",
"webpack": "^3.11.0",
"webpack-stream": "^4.0.1"
},
"dependencies": {
"babel-runtime": "^6.26.0",
"deepstream.io-client-js": "^2.3.0"
}
}
{
"files": [
"src/main.ts"
],
"compilerOptions": {
"outDir": "build/",
"target": "es5",
"noImplicitAny": true,
"sourceMap": true,
"declaration": true,
}
}
const path = require("path");
function DtsBundlePlugin() { }
DtsBundlePlugin.prototype.apply = function (compiler) {
compiler.plugin('done', function () {
var dts = require('dts-bundle');
dts.bundle({
name: "yanux-coordinator",
main: 'dist/build/main.d.ts',
out: '../lib.d.ts',
outputAsModuleFolder: true
});
});
};
module.exports = function (env, argv) {
plugins = [new DtsBundlePlugin()];
return {
entry: "./src/main.ts",
devtool: "source-map",
output: {
filename: "lib.js",
path: path.resolve(__dirname, "dist")
},
resolve: {
extensions: [".tsx", ".ts", ".jsx", ".js"]
},
module: {
rules: [
{ test: /\.tsx?$/, use: [{ loader: "babel-loader" }, { loader: "ts-loader" }], exclude: [/node_modules/] },
{ test: /\.jsx?$/, use: [{ loader: "babel-loader" }], exclude: [/node_modules/] },
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader", exclude: [/node_modules/] }
]
},
plugins: plugins
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment