I was able to get an absolute import path working on my webpack2 setup. Here is what I did. You need to configure tsconfig.json to support this. Here is an example: https://medium.com/@timwong/typescript-with-webpack2-how-to-do-import-with-absolute-path-f33b1826d330
Here is an example of my post.
Webpack2 Solution
var path = require('path'); module.exports = { module: { ... }, devtool: '...', resolve: { modules: [ path.resolve('./node_modules'), path.resolve('./app') ] }
Having defined resol.modules, we recommend Webpack to search for (aka) components using these paths as the root folder. TypeScript Configuration
OK, now that Webpack is good to go; what about TypeScript. If you use an editor such as Atom or VSCode, you will most likely see a highlighted error stating that TypeScript cannot find the modules. This is because TypeScript is not aware of this root module setting. We must also provide this information in tsconfig.json.
{ "compilerOptions": { "baseUrl": ".", "paths": { "*": [ "*", "app/*" ] } }
By defining the paths and baseUrl objects, we instruct the TypeScript compiler to search the application folder when resolving import statements. We hope that this simple example will help to unlock everyone who faces this configuration problem when we first start working with TypeScript and Webpack2.
Tim wong
source share