egoist / egoist/tsup

Why doesn't the flag --env.NODE_ENV and the option --onSuccess take effect?

Open
#1,108 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
275
PR merge metrics
No merged PRs in 30d

Description

I would like the generated results to be automatically executed following the successful completion of the compilation process, and for that compilation to utilize the configuration corresponding to the specific environment.

```json
"scripts": {
"dev": "tsup --watch --env.NODE_ENV development --onSuccess 'node dist/app.js'"
}
```
```ts
// tsup.config.ts
import { defineConfig } from "tsup";

const isDev = process.env.NODE_ENV === "development";

console.log("isDev", process.env.NODE_ENV);

export default defineConfig({
target: "es2020",
entry: ["lib/app.ts"],
outDir: "dist",
format: ["cjs", "esm"],
dts: !isDev,
minify: !isDev,
clean: true,
sourcemap: isDev
});
```

result:

![image](https://github.com/egoist/tsup/assets/41910836/145aeebe-5301-4c9c-b603-5cb394443d24)

Why doesn't the flag `--env.NODE_ENV` and the option `--onSuccess` take effect?
What should I do?

Contributor guide

Open the contributing guide

Research direction

Reproduce the package script using tsup.config.ts and the shown --watch, --env.NODE_ENV, and --onSuccess options. Start by tracing how the CLI loads tsup.config.ts and handles those options; done means the environment-specific settings are applied and node dist/app.js runs after a successful compilation.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system, cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.