Skip to content

Commit 70e7fe8

Browse files
authored
fix: use through2
1 parent 5523bc9 commit 70e7fe8

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

example/gulpfile.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,25 @@ const ts = require("typescript");
33
const rollup = require("rollup");
44
const typescriptPlugin = require("@rollup/plugin-typescript");
55
const { nodeResolve } = require("@rollup/plugin-node-resolve");
6+
const through2 = require("through2");
67

78
const LIB_SOURCE = "../src/**/*.ts";
89
const tsConfigPath = "../tsconfig.json";
910

1011
const transpileLibTypescript = () =>
11-
src(LIB_SOURCE, { sourcemaps: true }) // initialize sourcemaps
12-
.pipe(dest("../dist", { sourcemaps: "." })); // write sourcemaps to the same directory
13-
14-
function compileTypeScript(content, file) {
15-
const tsConfig = require(tsConfigPath);
16-
const result = ts.transpileModule(content.toString(), {
17-
compilerOptions: tsConfig.compilerOptions,
18-
fileName: file.path,
19-
});
20-
return result.outputText;
21-
}
12+
src(LIB_SOURCE, { sourcemaps: true })
13+
.pipe(through2.obj(function (file, _, cb) {
14+
if (file.isBuffer()) {
15+
const tsConfig = require(tsConfigPath);
16+
const result = ts.transpileModule(file.contents.toString(), {
17+
compilerOptions: tsConfig.compilerOptions,
18+
fileName: file.path,
19+
});
20+
file.contents = Buffer.from(result.outputText);
21+
}
22+
cb(null, file);
23+
}))
24+
.pipe(dest("../dist", { sourcemaps: '.' }));
2225

2326
const buildExample = (done) =>
2427
rollup

0 commit comments

Comments
 (0)