Skip to content

Commit c91d7da

Browse files
authored
Adding resolve.extentions to configuration sample
I think it makes sense to have it there, because people will pretty quickly run into `Module not found: Error: Can't resolve` and it is not easy to figure out the cause of this error by searching since it is very generic. Besides, I've extended second configuration example with additional rule; it is easier to copy paste it that ways, which people will likely do.
1 parent 964dc76 commit c91d7da

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

content/guides/webpack-and-typescript.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,18 @@ module.exports = {
5757
test: /\.tsx?$/,
5858
loader: 'ts-loader',
5959
exclude: /node_modules/,
60-
}
60+
},
6161
]
62-
}
62+
},
63+
resolve: {
64+
extensions: ["*", ".tsx", ".ts", ".js"]
65+
},
6366
};
6467
```
6568

6669
Here we specify our entry point to be __index.ts__ in our current directory,
6770
an output file called __bundle.js__
68-
and our TypeScript loader that is in charge of compiling our TypeScript file to JavaScript.
71+
and our TypeScript loader that is in charge of compiling our TypeScript file to JavaScript. We also add `resolve.extensions` to insruct webpack what file extensions to use when resolving Typescript modules.
6972

7073
## Typescript loaders
7174

@@ -111,8 +114,16 @@ module.exports = {
111114
test: /\.js$/,
112115
loader: "source-map-loader"
113116
},
117+
{
118+
enforce: 'pre',
119+
test: /\.js$/,
120+
use: "source-map-loader"
121+
}
114122
]
115123
},
124+
resolve: {
125+
extensions: ["*", ".tsx", ".ts", ".js"]
126+
},
116127
devtool: 'inline-source-map',
117128
};
118129
```
@@ -163,4 +174,4 @@ Here we declare a new module for svg by specifying any import that ends in __.sv
163174
If we wanted to be more explicit about this being a url we could define the type as string.
164175

165176
This applies not only to svg but any custom loader you may want to use which includes css, scss, json or any other file you may wish to load in your project.
166-
177+

0 commit comments

Comments
 (0)