xgqfrms / app-node-env

APP_ENV & one cli tools for customize env of APP
https://app-node-env.xgqfrms.xyz
MIT License
3 stars 0 forks source link

process.argv #14

Open xgqfrms opened 2 years ago

xgqfrms commented 2 years ago

process.argv

webpack.config.js

    let devServerPort = 8088;
    for (let args of process.argv) {
        if (args.startsWith('--port=')) {
            const port = args.replace('--port=', '');
            if (port) {
                devServerPort = parseInt(port);
            }
        }
    }
$ --port=8090 && npm run dev

$ --port=8090 npm run dev

优缺点

  1. 可以跨平台 ✅
  2. 代码侵入,多个 env 要写多个处理,代码冗余 ❌
  3. 不具有便携性,不利于分享 ❌