Parcel: how can i set three env in the project

Created on 30 Jan 2018  路  3Comments  路  Source: parcel-bundler/parcel

Choose one: is this a 馃悰 bug report or 馃檵 feature request?

馃帥 Configuration (.babelrc, package.json, cli command)

{
  "name": "zhengxian",
  "version": "1.0.0",
  "main": "index.js",
  "repository": "[email protected]:toa-h5/zhengxian.git",
  "license": "MIT",
  "scripts": {
    "dev": "cross-env production=true && parcel index.html ",
    "test": "rm -rf build && parcel build index.html --out-dir testFloder --public-url ./",
    "pro": "rm -rf build && parcel build index.html --out-dir proFloder --public-url ./"
  },
  "browserslist": [
    "iOS >= 5",
    "Android >= 4"
  ],
  "dependencies": {
    "@yzt/native_h5": "^5.3.0",
    "prop-types": "^15.6.0",
    "react": "^16.2.0",
    "react-dom": "^16.2.0"
  },
  "devDependencies": {
    "autoprefixer": "^7.2.5",
    "axios": "^0.17.1",
    "babel-polyfill": "^6.26.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "mobx": "^3.4.1",
    "node-sass": "^4.7.2",
    "parcel-bundler": "^1.4.1",
    "postcss-modules": "^1.1.0",
    "react-router": "^4.2.0"
  }
}

馃 Expected Behavior

I hope if i run yarn run test, i can build file with the config of test , because the url in test is different from production

馃槸 Current Behavior

i see the cli file , if i have the command build, the NODE_ENV will be set to production,and only development and production in the file , i hope get anothertest

馃拋 Possible Solution

馃敠 Context

馃捇 Code Sample

馃實 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.41|
| Node | 8.91|
| npm/Yarn | 1.3.2 |
| Operating System | mac ox|

Feature

Most helpful comment

Yeah, there are times where I need a development build.

All 3 comments

why the cli.js need to set the env

if (command.name() === 'build') {
    process.env.NODE_ENV = 'production';
  } else {
    process.env.NODE_ENV = process.env.NODE_ENV || 'development';
  }

set the env from the package.json is a good way

"scripts": {
    "dev": "cross-env NODE_ENV=development parcel index.html --open",
    "test": "rm -rf testFloder && cross-env NODE_ENV=development parcel build index.html --no-minify --out-dir testFloder --public-url ./",
    "pro": "rm -rf proFloder && cross-env NODE_ENV=production parcel build index.html --out-dir proFloder --public-url ./"
  }

Yeah, there are times where I need a development build.

Fixed by #1600

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oliger picture oliger  路  3Comments

davidnagli picture davidnagli  路  3Comments

termhn picture termhn  路  3Comments

jzimmek picture jzimmek  路  3Comments

mnn picture mnn  路  3Comments