Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

supply resolveTypeReferenceDirective to ts-loader #10

Merged
merged 4 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,33 @@ module.exports = {
rules: [{
test: /\.ts$/,
loader: require.resolve('ts-loader'),
options: PnpWebpackPlugin.tsLoaderOptions(),
options: PnpWebpackPlugin.tsLoaderOptions({
// ... regular options go there ...
}),
}],
},
};
```

If you have any options you want to pass to `ts-loader`, just pass them as parameter of the `tsLoaderOptions` function and it will take care of forwarding them properly.

## `fork-ts-checker-webpack-plugin` integration

We also provide an integration for `fork-ts-checker-webpack-plugin`, in a similar way to what we do with `ts-loader`. Here's an example:

```js
const ForkTsCheckerWebpackPlugin = require(`fork-ts-checker-webpack-plugin`);
const PnpWebpackPlugin = require(`pnp-webpack-plugin`);

module.exports = {
plugins: [
new ForkTsCheckerWebpackPlugin(PnpWebpackPlugin.forkTsCheckerOptions({
// ... regular options go there ...
}),
],
};
```

## License (MIT)

> **Copyright © 2016 Maël Nison**
Expand Down
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require(`path`);
const {resolveModuleName} = require(`ts-pnp`);

let pnp;

Expand Down Expand Up @@ -140,5 +141,11 @@ module.exports.bind = (filter, module, dependency) => pnp ? {
};

module.exports.tsLoaderOptions = (options = {}) => pnp ? Object.assign({}, options, {
resolveModuleName: require('ts-pnp').resolveModuleName,
resolveModuleName: resolveModuleName,
resolveTypeReferenceDirective: resolveModuleName,
}) : options;

module.exports.forkTsCheckerOptions = (options = {}) => pnp ? Object.assign({}, options, {
resolveModuleNameModule: require.resolve(`./ts`),
resolveTypeReferenceDirectiveModule: require.resolve(`./ts`),
}) : options;
9 changes: 9 additions & 0 deletions ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const {resolveModuleName} = require(`ts-pnp`);

exports.resolveModuleName = (typescript, moduleName, containingFile, compilerOptions, resolutionHost) => {
return resolveModuleName(moduleName, containingFile, compilerOptions, resolutionHost, typescript.resolveModuleName);
};

exports.resolveTypeReferenceDirective = (typescript, moduleName, containingFile, compilerOptions, resolutionHost) => {
return resolveModuleName(moduleName, containingFile, compilerOptions, resolutionHost, typescript.resolveTypeReferenceDirective);
};