Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require("cross-env") All In One ❌ #6

Open
xgqfrms opened this issue Oct 15, 2021 · 3 comments
Open

require("cross-env") All In One ❌ #6

xgqfrms opened this issue Oct 15, 2021 · 3 comments

Comments

@xgqfrms
Copy link
Owner

xgqfrms commented Oct 15, 2021

require("cross-env") All In One

#!/usr/bin/env node

/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms 2021.10.14
 *
 * @description PORT_ENV Generator
 * @augments
 * @example spe PORT_ENV=8090
 *
 */

// ❌  not support 
const crossEnv = require("cross-env");

// const shell = require("shelljs");
// const fs = require("fs");

const {
  version,
  argv,
  platform,
  // versions,
  // arch,
  // env,
} = process;

let command = ``;

// old version cross-env (dist)
if (isPureNumber(env)) {
  // npm / yarn
  // 单个 process 直接执行 ✅
  command = `crossEnv ${key}=${env} npm run dev`;
  // command = `./node_modules/cross-env/dist/bin/cross-env.js ${key}=${env} npm run dev`;
  // command = `./node_modules/cross-env/dist/bin/cross-env.js ${key}=${env} yarn dev`;
} else {
  // 单个 process 直接执行 ✅
  command = `crossEnv ${key}='${env}' npm run dev`;
  // command = `./node_modules/cross-env/dist/bin/cross-env.js ${key}='${env}' npm run dev`;
  // command = `./node_modules/cross-env/dist/bin/cross-env.js ${key}='${env}' yarn dev`;
}
@xgqfrms xgqfrms changed the title require("cross-env") require("cross-env") All In One Oct 15, 2021
@xgqfrms
Copy link
Owner Author

xgqfrms commented Oct 15, 2021

cross-env & cross-env-shell

https://github.com/kentcdodds/cross-env#cross-env-vs-cross-env-shell

image

.npmrc

kentcdodds/cross-env#192 (comment)

cmd => powershell

# in .npmrc
script-shell = "C:\\windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"

# using the CLI
$ npm config set script-shell = "C:\\windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"

@xgqfrms
Copy link
Owner Author

xgqfrms commented Oct 15, 2021

kentcdodds/cross-env#257

@xgqfrms
Copy link
Owner Author

xgqfrms commented Oct 15, 2021

JSON.stringify(process.env.NODE_ENV)

https://stackoverflow.com/questions/65844864/cross-env-not-changing-env-variable-when-running-yarn

webpack.config.js

{
  // ...
  plugins: [
    // ...
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
    }),
  ],
}

@xgqfrms xgqfrms changed the title require("cross-env") All In One require("cross-env") All In One ❌ Oct 15, 2021
@xgqfrms xgqfrms mentioned this issue Oct 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant