Skip to content
This repository was archived by the owner on Dec 1, 2019. It is now read-only.

Commit e4498df

Browse files
committed
feat: more options, better error messages from ts
1 parent 0a141c3 commit e4498df

File tree

7 files changed

+32
-58
lines changed

7 files changed

+32
-58
lines changed

README.md

+26-48
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
[![Join the chat at https://gitter.im/s-panferov/awesome-typescript-loader](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/s-panferov/awesome-typescript-loader?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
44
[![Build Status](https://travis-ci.org/s-panferov/awesome-typescript-loader.svg?branch=master)](https://travis-ci.org/s-panferov/awesome-typescript-loader)
55

6-
TypeScript loader for Webpack. This project was started as a fork of https://github.com/andreypopp/typescript-loader.
7-
Thanks to @andreypopp for the great project.
8-
9-
The main goal of this loader is to support the **watch** mode and *webpack-dev-server* with **incremental** compilation.
10-
There are a lot of problems in other TypeScript loaders that are fixed here.
11-
126
## Installation
137

148
```
@@ -44,7 +38,7 @@ module.exports = {
4438

4539
// Currently we need to add '.ts' to the resolve.extensions array.
4640
resolve: {
47-
extensions: ['', '.ts', '.webpack.js', '.web.js', '.js']
41+
extensions: ['', '.ts', '.tsx', '.js', '.jsx']
4842
},
4943

5044
// Source maps support ('inline-source-map' also works)
@@ -64,10 +58,6 @@ module.exports = {
6458

6559
After that, you will be able to build TypeScript files with webpack.
6660

67-
## TS defaults
68-
69-
* target = 'es5'
70-
7161
## tsconfig.json
7262

7363
You can use the tsconfig.json file to configure your compiler and loader:
@@ -84,6 +74,26 @@ You can use the tsconfig.json file to configure your compiler and loader:
8474
}
8575
```
8676

77+
## Supported TypeScript
78+
79+
`[email protected]` aims to support only `[email protected]` and `webpack@2x`, if you need old compilers please use
80+
`1.x` or `0.x` versions.
81+
82+
## Advansed path resolution in TypeScript 2.0
83+
84+
If you want to use new `paths` and `baseUrl` feature of TS 2.0 please include `TsConfigPathsPlugin`.
85+
This feature is available only for `[email protected]`.
86+
87+
```
88+
var TsConfigPathsPlugin = require('awesome-typescript-loader').TsConfigPathsPlugin;
89+
90+
resolve: {
91+
plugins: [
92+
new TsConfigPathsPlugin(/* { tsconfig, compiler } */)
93+
]
94+
}
95+
```
96+
8797
## Loader options
8898

8999
### compiler *(string) (default='typescript')*
@@ -93,13 +103,13 @@ set to the NPM name of the compiler, e.g. *ntypescript* or the path to a package
93103
Note that the compiler must be installed in **your** project. You can also use
94104
nightly versions.
95105

96-
### emitRequireType *(boolean) (default=false)*
106+
### disableFastEmit (boolean) (default=false)*
97107

98-
Specify whether or not the loader emits webpacks's require type.
108+
Disable fast `transpileModule` emit mode. Disables automatically when you set `declaration: true`.
99109

100-
### library *(string) (default='es5' possible='es6')*
110+
### emitRequireType *(boolean) (default=false)*
101111

102-
Allows the use of libraries other than the `target`'s default one. Useful when you want to use ES6 library with ES5 target. Additionally you might use `library=es6` with Node.
112+
Specify whether or not the loader emits webpacks's require type.
103113

104114
### instanceName *(string) (default='default')*
105115

@@ -174,42 +184,10 @@ Use pre-compiled files if any. Files must be named as `{filename}.js` and `{file
174184

175185
Directory when cache is stored.
176186

177-
### resolveGlobs *(string) (default=true)*
178-
179-
Invoke glob resolver using 'filesGlob' and 'exclude' sections of `tsconfig`.
180-
181187
### skipDeclarationFilesCheck *(string) (default=false)*
182188

183189
Skip declaration files typechecking. Use this only if you understand consequences.
184190

185191
## Compiler options
186192

187-
You can pass compiler options inside loader query string or in tsconfig file.
188-
189-
## Using with --watch or webpack-dev-server
190-
191-
This loader supports both `--watch` and `webpack-dev-server` modes. It handles file dependencies
192-
using internal webpack dependency markers. When you change a file, the loader recompiles all the dependencies.
193-
194-
## External Modules
195-
196-
The most natural way to structure your code with TypeScript and webpack is to use [external modules](https://github.com/Microsoft/TypeScript/wiki/Modules#going-external), and these work as you would expect.
197-
198-
```
199-
npm install --save react
200-
```
201-
202-
```typescript
203-
import * as React from 'react';
204-
```
205-
206-
## Internal Modules
207-
208-
This project doesn't aim to support internal modules, because it's hard to resolve dependencies for the watch mode. Of course, you can still use them without watch, but this function is **unstable**.
209-
210-
## Declaration files
211-
212-
All declaration files should be resolvable from the entry file.
213-
The easiest way to do this is to create a `references.d.ts` file which contains
214-
references to all of your declaration files. Then reference
215-
`references.d.ts` from your entry file.
193+
You can pass compiler options inside loader query string or in tsconfig file.

src/checker-runtime.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class Host implements ts.LanguageServiceHost {
9090
getScriptSnapshot(fileName: string) {
9191
let file = env.files[fileName];
9292
if (!file) {
93-
throw new Error(`Requested file is unknown: ${ fileName }`);
93+
return null;
9494
}
9595
return env.compiler.ScriptSnapshot.fromString(file.text);
9696
}

src/deps.ts

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export class FileAnalyzer {
6868
let options = this.state.compilerConfig.options;
6969
let ts = this.state.ts;
7070
let deps = this.state.fileAnalyzer.dependencies;
71-
7271
let imports: string[] = [];
7372

7473
imports.push.apply(imports, info.importedFiles

src/host.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class Host implements ts.LanguageServiceHost {
4949
getScriptSnapshot(fileName) {
5050
let file = this.state.getFile(fileName);
5151
if (!file) {
52-
throw new Error(`Requested file is unknown: ${ fileName }`);
52+
return null;
5353
}
5454
return this.state.ts.ScriptSnapshot.fromString(file.text);
5555
}

src/index.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,8 @@ function transform(webpack: IWebPack, instance: ICompilerInstance, fileName: str
144144
let resultSourceMap = null;
145145
let state = instance.tsState;
146146

147-
if (state.compilerConfig.options.declaration) {
148-
// can't use fastEmit with declaration generation
149-
147+
let useSlowEmit = state.compilerConfig.options.declaration || state.loaderConfig.disableFastEmit
148+
if (useSlowEmit) {
150149
let output = state.emit(fileName);
151150
let result = helpers.findResultFor(output, fileName);
152151

@@ -164,8 +163,6 @@ function transform(webpack: IWebPack, instance: ICompilerInstance, fileName: str
164163
resultText = result.text;
165164
resultSourceMap = result.sourceMap;
166165
} else {
167-
// Use fast emit
168-
169166
let result = state.fastEmit(fileName);
170167
resultText = result.text;
171168
resultSourceMap = result.sourceMap;

src/instance.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ export interface LoaderConfig {
8282
skipDeclarationFilesCheck?: boolean;
8383
useCache?: boolean;
8484
cacheDirectory?: string;
85-
resolveGlobs?: boolean;
86-
library: string;
85+
disableFastEmit?: boolean;
8786
}
8887

8988
export type QueryOptions = LoaderConfig & ts.CompilerOptions;

src/paths-plugin.ts

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export class PathsPlugin implements ResolverPlugin {
106106
resolver.apply(new ModulesInRootPlugin("module", this.absoluteBaseUrl, "resolve"));
107107
}
108108

109+
109110
mappings.forEach(mapping => {
110111
resolver.plugin(this.source, this.createPlugin(resolver, mapping));
111112
});

0 commit comments

Comments
 (0)