Skip to content

xgqfrms/set-process-env

Repository files navigation

set-process-env

set-process-env by linux bash command without need git ignore the .env file

https://www.npmjs.com/package/set-process-env

install

$ yarn global add set-process-env
# OR
$ npm i -g set-process-env

usage

# PORT_ENV for webpack & npm script dev
$ spe PORT_ENV=8090

demo

// package.json

// ⚠️ precondition (cross-env@5.2.0, &  npm scripts has dev command)
// ⚠️ 前置条件 (cross-env@5.2.0 & npm scripts has dev command)

{
  // ...
  "scripts": {
    "dev": "webpack-dev-server --inline",
    // "dev": "cross-env NODE_OPTIONS='--max-old-space-size=8192' cross-env NODE_ENV=development webpack-dev-server --inline",
    // ...
  },
  // ...
}
// webpack.config.js
const PORT = process.env.PORT_ENV || 8080;

console.log('PORT_ENV =', process.env.PORT_ENV);
// console.log('\n process.env.PORT_ENV =', process.env.PORT_ENV);
// console.log('\n process.env.NODE_ENV =', process.env.NODE_ENV);
// console.log('\n process.env.NODE_OPTIONS =', process.env.NODE_OPTIONS);
// console.log('\n ✅ ');

// const ip = require('ip');
// const hostIp = ip.address();
const config = {
  // ...
  devServer: {
    // ...
    // host: hostIp,
    port: PORT_ENV || 8080,
    proxy: [
      {
        context: ['/web/api/'],
        // dev
        target: 'https://web-dev.xgqfrms.xyz',
        // prod
        // target: 'https://web-prod.xgqfrms.xyz',
      },
    ],
  },
};

module.exports = config;

image

multi env

$ spe PORT_ENV=8090 PROXY_ENV=pre

image

image

Travis CI

https://travis-ci.org/xgqfrms/set-process-env/builds

https://www.cnblogs.com/xgqfrms/p/12851281.html

refs

https://www.npmjs.com/package/app-node-env

Releases

No releases published

Packages

No packages published