banner
ming5ming

ming5ming

⭐一起去追那遥不可及的星⭐ 正在赛马!

Node env

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

// 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:

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

in esbuild config:

//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;
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.