Skip to content

Commit c181604

Browse files
committed
fix: adjust webpack config for legacy TypeScript versions
1 parent 9585a68 commit c181604

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/webpackConfigFactory.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const root = path.resolve(__dirname, '..');
88

99
module.exports = function webpackConfigFactory(libname, dirname, config = {}) {
1010
return function (env, argv) {
11+
const tsVersion = ts.version;
12+
const isLegacyTs = parseInt(tsVersion.split('.')[0]) < 5;
13+
1114
return defaultsDeep(config, {
1215
entry: path.resolve(dirname, 'src/index.ts'),
1316
devtool: argv.mode !== 'production' ? 'inline-source-map' : false,
@@ -34,15 +37,22 @@ module.exports = function webpackConfigFactory(libname, dirname, config = {}) {
3437
test: /\.ts?$/,
3538
loader: 'ts-loader',
3639
exclude: /node_modules/,
40+
options: {
41+
compilerOptions: {
42+
declaration: true,
43+
declarationDir: isLegacyTs ? path.resolve(dirname, 'src') : undefined
44+
}
45+
}
3746
}
3847
]
3948
},
4049
plugins: [
4150
new DtsBundleWebpack({
4251
name: libname,
43-
main: 'src/index.d.ts',
52+
main: isLegacyTs ? 'src/index.d.ts' : 'src/index.d.ts',
4453
out: path.join(dirname, 'index.d.ts'),
45-
removeSource: true
54+
removeSource: true,
55+
outputAsModuleFolder: true
4656
}),
4757
]
4858
});

0 commit comments

Comments
 (0)