Skip to content

Commit 5b2e629

Browse files
committed
Update webpack for ts
1 parent 470d466 commit 5b2e629

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/webpack.config.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ export default (opts = {}) => {
4343
}));
4444
}
4545

46+
const outPath = path.resolve(dirCwd, args.output);
47+
const pathTsConf = rootResolve('tsconfig.json');
48+
const tsConfig = fs.existsSync(pathTsConf) ? require(pathTsConf) : {};
49+
const optsTsCmpl = tsConfig.compilerOptions || {};
50+
4651
let config = {
4752
entry: path.resolve(dirCwd, args.entry),
4853
mode: isProd ? 'production' : 'development',
@@ -62,14 +67,28 @@ export default (opts = {}) => {
6267
})],
6368
},
6469
output: {
65-
path: path.resolve(dirCwd, args.output),
70+
path: outPath,
6671
filename: `${name}.min.js`,
6772
library: name,
6873
libraryTarget: 'umd',
6974
globalObject: `typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : this)`,
7075
},
7176
module: {
7277
rules: [{
78+
test: /\.tsx?$/,
79+
loader: require.resolve('ts-loader'),
80+
exclude: /node_modules/,
81+
options: {
82+
context: rootResolve(''),
83+
configFile: pathTsConf,
84+
compilerOptions: {
85+
...(
86+
optsTsCmpl.declaration && !optsTsCmpl.declarationDir &&
87+
{ declarationDir: `${outPath}/types` }
88+
)
89+
}
90+
}
91+
}, {
7392
test: /\.js$/,
7493
loader: 'babel-loader',
7594
include: /src/,
@@ -80,6 +99,9 @@ export default (opts = {}) => {
8099
},
81100
}],
82101
},
102+
resolve: {
103+
extensions: ['.tsx', '.ts', '.js'],
104+
},
83105
plugins: plugins,
84106
};
85107

0 commit comments

Comments
 (0)