xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

npm & app-node-env All In One

npm & app-node-env All In One

app-node-env

$ npm i -g app-node-env
# OR
$ yarn global add app-node-env

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

npx

eric@rpi4b:~/Desktop/node-playground $ ane PORT=8888
-bash: ane:未找到命令
eric@rpi4b:~/Desktop/node-playground $ npm-do ane PORT=8888
-bash: npm-do:未找到命令
eric@rpi4b:~/Desktop/node-playground $ npx ane PORT=8888

🚀 your node.js version = 18

🎮 creating...

🎉 finished!
eric@rpi4b:~/Desktop/node-playground $ ./node_modules/app-node-env/ane PORT=8888

🚀 your node.js version = 18

🎮 creating...

🎉 finished!
eric@rpi4b:~/Desktop/node-playground $

npx

http://disq.us/p/2w3phvp

https://2ality.com/2016/01/locally-installed-npm-executables.html

Usage

cli

# node
$ ane env=dev
# OR
$ node ane env=dev

demos

  1. custom webpack devServer port
# global install
$ yarn global add app-node-env

# PORT_ENV for webpack
$ ane PORT_ENV=8090

// webpack.config.js
const PORT_ENV = require('./env.js');

console.log('PORT_ENV =', PORT_ENV);

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

  1. control env
# global install
$ yarn global add app-node-env

# APP_ENV for webpack
$ ane APP_ENV=dev
# $ ane APP_ENV=prod

// webpack.config.js
const APP_ENV = require('./env.js');

console.log('APP_ENV =', APP_ENV);

let target = '';
if(APP_ENV === 'dev') {
  target = 'https://web-dev.xgqfrms.xyz';
} else {
  target = 'https://web-prod.xgqfrms.xyz';
}

const config = {
  // ...
  devServer: {
    // ...
    proxy: [
      {
        context: ['/web/api/'],
        target: target,
        // dev
        // target: 'https://web-dev.xgqfrms.xyz',
        // prod
        // target: 'https://web-prod.xgqfrms.xyz',
      },
    ],
  },
};

module.exports = config;

refs

https://app-node-env.xgqfrms.xyz

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

https://npm.runkit.com/app-node-env



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2019-05-20 22:05  xgqfrms  阅读(233)  评论(3编辑  收藏  举报