Skip to content

Commit 3e46741

Browse files
committed
feat: 🎸 add "transpileOnly" option to skip type check
Issues: #54
1 parent 78180a6 commit 3e46741

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

Diff for: ‎README.md

+28
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@ const options = {
377377
compilerOptions: {
378378
module: 'es2015',
379379
},
380+
381+
/**
382+
* Type checking can be skipped by setting 'transpileOnly: true'.
383+
* This speeds up your build process.
384+
*/
385+
transpileOnly: true,
380386
},
381387
382388
/** Use a custom preprocess method by passing a function. */
@@ -422,3 +428,25 @@ ul
422428
![image](https://user-images.githubusercontent.com/2388078/63219174-8d4d8b00-c129-11e9-9fb0-56260a125155.png)
423429
424430
If you have configured `svelte-preprocess` to use some kind of preprocessor and `svelte-vscode` is displaying errors like it's ignoring your preprocess configuration, that's happening because `svelte-vscode` needs to know how to preprocess your components. `svelte-vscode` works by having a svelte compiler running on the background and you can configure it by [creating a `svelte.config.js`](#with-svelte-vs-code) file on your project's root. Please check this document [With Svelte VS Code](#with-svelte-vs-code) section.
431+
432+
### My `typescript` compilation is sloooooooow
433+
434+
If you have a medium-to-big project, the typescript processor might start to get slow. If you already have an IDE type checking your code, you can speed up the transpilation process by setting `transpileOnly` to `true`:
435+
436+
```js
437+
const preprocess = require('svelte-preprocess')
438+
...
439+
{
440+
...svelteOptions,
441+
preprocess: preprocess({
442+
typescript: {
443+
// skips type checking
444+
transpileOnly: true,
445+
compilerOptions: {
446+
...
447+
},
448+
},
449+
})
450+
}
451+
...
452+
```

Diff for: ‎src/transformers/typescript.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,23 @@ module.exports = ({ content, filename, options }) => {
195195
allowNonTsExtensions: true,
196196
}
197197

198-
const { code, map, diagnostics } = compileFileFromMemory(compilerOptions, {
199-
filename,
200-
content,
201-
})
198+
let code, map, diagnostics
199+
if (options.transpileOnly || compilerOptions.transpileOnly) {
200+
;({
201+
outputText: code,
202+
sourceMapText: map,
203+
diagnostics,
204+
} = ts.transpileModule(content, {
205+
fileName: filename,
206+
compilerOptions: compilerOptions,
207+
reportDiagnostics: options.reportDiagnostics !== false,
208+
}))
209+
} else {
210+
;({ code, map, diagnostics } = compileFileFromMemory(compilerOptions, {
211+
filename,
212+
content,
213+
}))
214+
}
202215

203216
if (diagnostics.length > 0) {
204217
// could this be handled elsewhere?

Diff for: ‎test/transformers/typescript.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ describe('transformer - typescript', () => {
6969
})
7070
return expect(preprocess(template, opts)).rejects.toThrow('TS6046')
7171
})
72+
73+
it('should not type check if "transpileOnly: true"', async () => {
74+
const opts = getAutoPreprocess({
75+
typescript: {
76+
transpileOnly: true,
77+
compilerOptions: {
78+
module: 'ESNext',
79+
},
80+
},
81+
})
82+
const { code } = await preprocess(template, opts)
83+
return expect(code).toContain(getFixtureContent('script.js'))
84+
})
7285
})
7386

7487
describe('code errors', () => {

0 commit comments

Comments
 (0)