-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
37 lines (34 loc) · 971 Bytes
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
devtool: 'inline-source-map',
entry: './src/index.ts',
plugins: [new HtmlWebpackPlugin({ template: './index.html' })],
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
plugins: [
{
apply(resolver) {
resolver.getHook('raw-file').tapAsync('ESM resolver', (request, _, callback) => {
const adjustedReq = {
...request,
path: request.path?.replace(/\.js(x)?$/, '.ts$1'),
relativePath: request.relativePath?.replace(/\.js(x)?$/, '.ts$1'),
}
if (request.path === adjustedReq.path) {
return callback()
}
resolver.doResolve(resolver.ensureHook('file'), adjustedReq, 'ESM resolver', callback)
})
},
},
],
},
}