I have two files: index.ts and pixel.ts
Index has a bunch of functions and two classes
Pixel imports one of the classes and a function from index and instantiates the class, then passes it to the function.
I have this tsup config
/* eslint-disable no-var */
import { defineConfig, Options } from "tsup"
import pkg from './package.json'
var commonConfig: Options = {
clean: true,
splitting: false,
sourcemap: true,
env: {
__VERSION__: JSON.stringify(`${pkg.version}.${Date.now()}`),
__TARGET__: JSON.stringify("node"),
},
target: "node14",
outDir: "dist",
}
export default defineConfig([
{
entry: [
"src/pixel.ts"
],
...commonConfig,
format: ["iife"],
target: "es5",
env: {
...commonConfig.env,
__TARGET__: JSON.stringify("web"),
}
},
// {
// entry: [
// "src/index.ts",
// "src/types.ts",
// "src/examples.ts",
// ],
// ...commonConfig,
// format: ["esm", "cjs"],
// dts: true,
// },
])
...trying to cross compile esm modules, cjs modules for node14 and es5 for the web.
However, the output looks like this for the es5 build:
CLI Building entry: src/pixel.ts
CLI Using tsconfig: tsconfig.json
CLI tsup v6.2.2
CLI Using tsup config: /sdk/tsup.config.ts
CLI Target: es5
CLI Cleaning output folder
IIFE Build start
IIFE dist/pixel.global.js 47.72 KB
IIFE dist/pixel.global.js.map 40.93 KB
IIFE ⚡️ Build success in 62ms
Which then crashes with import declarations may only appear at top level of a module
but obviously I want this pixel to work in very old browsers.
I call tsup like this:
tsup
and it reads the config file above in full.
Latest versions.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too