Node env

index.js will read process.env.* in .env
But u can require dotenv to get env in command line:

Copy
// package.json
"scripts": {
"build:dev": "webpack",
"build:prod": "cross-env NODE_ENV=production webpack"
},

// .env
NODE_ENV=development

// webpack.config.js
const dotenv = require("dotenv")

dotenv.config()
console.log(process.env.NODE_ENV)

process.exit(0)

// console output
npm run build:dev // "development"
npm run build:prod // "production"

Also, in webpack config:

Copy
"build:prod": "webpack --node-env=production"

in esbuild config:

Copy
//build.js
const esbuild = require('esbuild');

esbuild
.build({
entryPoints: ['./src/ts/variables.ts', './src/ts/elements.ts', './src/ts/form.ts'],
outdir: './public/js',
bundle: true,
minify: true,
sourcemap: false,
format: 'esm',
tsconfig: './tsconfig.json',
define: {
'process.env.TITLE': '"This is a Title"',
'process.env.VERSION': '"1.0.0"'
}
})
//index.js
const title = process.env.TITLE;
const version = process.env.VERSION;