I want to bundle my react library, I created some simple .ts file, exported single variable and built with webpack. But I receive empty file main.js bundle. There is nothing there. What is wrong?
index.external.ts
export const Foo = "blablabla";
or
export default { Foo };
webpack.config.js
const path = require("path");
const webpack = require("webpack");
module.exports = {
mode: "production",
entry: {
main: "./components/src/index.external.ts",
},
module: {
rules: [
{
test: /.svg$/i,
use: {
loader: "svg-inline-loader",
options: { removeTags: true, removingTags: ["circle"], idPrefix: true },
},
include: /.svg$/,
},
{
test: /.(j|t)sx?$/,
use: [
{
loader: "babel-loader?cacheDirectory=true",
options: {
rootMode: "upward",
},
},
],
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
output: {
filename: "[name]/index.js",
path: path.resolve(__dirname, "dist"),
},
externals: {
react: "react",
"react-dom": "react-dom",
},
};
and babel.config I use
module.exports = (api) => {
api.cache.using(() => process.env.NODE_ENV);
const hmr = !!process.env.WEBPACK_DEV_SERVER;
return {
presets: [
[
"@babel/env",
{
targets: [
"chrome >= 57",
"edge >= 14",
"firefox >= 52",
"safari >= 10.1",
"opera >= 44",
"ios_saf >= 10.3",
"android >= 56",
"and_chr 57",
],
useBuiltIns: "usage",
corejs: {
version: 3,
proposals: true,
},
debug: false,
},
],
[
"@babel/preset-react",
{
runtime: "automatic",
development: process.env.NODE_ENV === "development",
importSource: "@welldone-software/why-did-you-render",
},
],
[
"@babel/typescript",
{
isTSX: true,
allExtensions: true,
},
],
],
plugins: [
"@babel/plugin-proposal-export-default-from",
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-proposal-class-properties",
["@babel/plugin-proposal-private-methods", { loose: false }],
["@babel/plugin-proposal-private-property-in-object", { loose: false }],
].filter(Boolean),
};
};
I got some issue with SO regarding “it looks like your post is mostly code” thats why I put this message below