3
votes

I have installed a .d.ts file (namely, type definitions for p2.js library) as external (non-global) typings module with the following command:

typings install p2=github:schteppe/p2.js/index.d.ts#9d56924

I then use it in my TypeScript code like this:

import * as p2 from 'p2';

This import appears in the compiled javascript:

var p2 = require('p2');

But, obviously, I do not need it there, since the p2 external module contains only type definitions, not actual code. I then run webpack on the TypeScript's output and it fails to compile with

...Module not found: Error: Cannot resolve module 'p2'...

What is the right way to use this external module so that TypeScript and my IDE (Atom with atom-typescript plugin) see the definitions, but no require call for it gets included in the TypeScript output?

2

2 Answers

1
votes

webpack supports configuring externals.

In your case this would be
externals: [ { "p2": true}]

More info on handling externals in the webpack documentation: webpack.github.io/docs/configuration.html#externals.

Edit: updated with new information from comments