Skip to content

Commit

Permalink
Add transpileOnly support for TS projects if needed (#497)
Browse files Browse the repository at this point in the history
* Add transpileOnly support for TS projects if needed.
This allows us to build faster while we are developing.
(As we are not much interest about the type accuracy)

With some tests, we can gain upto 2X time reduction when building.
I assume the benefit will be more than this for massive projects.

* Add a test case.
  • Loading branch information
arunoda authored Jan 4, 2020
1 parent ec49f6e commit 60214d2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Options:
-e, --external [mod] Skip bundling 'mod'. Can be used many times
-q, --quiet Disable build summaries / non-error outputs
-w, --watch Start a watched build
-t, --transpile-only Use transpileOnly option with the ts-loader
--v8-cache Emit a build using the v8 compile cache
`;

Expand Down Expand Up @@ -135,7 +136,9 @@ async function runCmd (argv, stdout, stderr) {
"-q": "--quiet",
"--watch": Boolean,
"-w": "--watch",
"--v8-cache": Boolean
"--v8-cache": Boolean,
"--transpile-only": Boolean,
"-t": "--transpile-only",
}, {
permissive: false,
argv
Expand Down Expand Up @@ -223,6 +226,7 @@ async function runCmd (argv, stdout, stderr) {
cache: args["--no-cache"] ? false : undefined,
watch: args["--watch"],
v8cache: args["--v8-cache"],
transpileOnly: args["--transpile-only"],
quiet
}
);
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ module.exports = (
v8cache = false,
filterAssetBase = process.cwd(),
quiet = false,
debugLog = false
debugLog = false,
transpileOnly = false
} = {}
) => {
if (!quiet) {
Expand Down Expand Up @@ -177,6 +178,7 @@ module.exports = (
{
loader: eval('__dirname + "/loaders/ts-loader.js"'),
options: {
transpileOnly,
compiler: eval('__dirname + "/typescript.js"'),
compilerOptions: {
outDir: '//',
Expand Down
4 changes: 4 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,9 @@
expect (code, stdout, stderr) {
return code === 1 && stderr.toString().indexOf('ts-error.ts(3,16)') !== -1 && stderr.toString().split('\n').length < 10;
}
},
{
args: ["run", "-t", "test/fixtures/with-type-errors/ts-error.ts"],
expect: { code: 0 }
}
]
5 changes: 5 additions & 0 deletions test/fixtures/with-type-errors/ts-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require.extensions['.asdf'] = function () {};

function p (x: Y) {

}
5 changes: 5 additions & 0 deletions test/fixtures/with-type-errors/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"target": "es2015"
}
}

0 comments on commit 60214d2

Please sign in to comment.