Skip to content

Instantly share code, notes, and snippets.

@forabi
Last active December 18, 2019 08:15
Show Gist options
  • Save forabi/55a939ccbf82c9963ab54a369ad95bc7 to your computer and use it in GitHub Desktop.
Save forabi/55a939ccbf82c9963ab54a369ad95bc7 to your computer and use it in GitHub Desktop.
Configuring Webpack and TypeScript for relative module imports
// src/store/reducers/workspace/canvas.ts
import { handleActions } from 'utils/store';
/// ...
// src/utils/store.ts
// ..
export function handleActions(map, defaultState) {
// ..
}
// ...
{
"compilerOptions": {
// ... your standard TS config here
"paths": {
"*": [
"*",
"src/*"
]
}
}
}
const config = {
// your standard Webpack config here
// ...
resolve: {
// ...
modules: [
// Here is the important part
path.join(__dirname, 'src'),
'node_modules',
],
},
};
module.exports = config;
@eduard-malakhov
Copy link

Works like charm, thank you for sharing this! For me, it even worked with less configuration: I hadn't had to specify path mapping "*": [ "*", "src/*" ] in my tsconfig.json, only baseUrl: './src'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment