In the process of developing my TypeScript library, I encountered an issue with bundling it using Webpack. Despite trying different configurations and loaders like ts-loader and awesome-ts-loader, I could not get the bundled package to work properly. Every time I attempted to import the bundled package, it returned "undefined."
Here is an excerpt from my tsconfig.json file:
{
"compilerOptions": {
"declaration": true,
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "es6",
"target": "es6",
"resolveJsonModule": true,
"moduleResolution": "node"
},
"exclude": [
"node_modules"
]
}
I also included my webpack configuration below:
const path = require('path');
module.exports = {
entry: './src/index.ts',
mode: 'production',
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: '/node_modules/'
}
]
},
resolve: {
extensions: ['.ts']
},
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'dist'),
library: '',
libraryTarget: 'commonjs2',
libraryExport: 'default'
}
};
Despite numerous attempts and hours of troubleshooting, I have not been able to resolve this issue. If anyone has any insights or suggestions that I have not already tried, I would greatly appreciate it.
Thank you.