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

process.env is empty object #7

Open
blockscoped opened this issue Mar 8, 2017 · 6 comments
Open

process.env is empty object #7

blockscoped opened this issue Mar 8, 2017 · 6 comments

Comments

@blockscoped
Copy link

My rollup config plugins:

process.env.MY_PROP = 'test';

const plugins = [
  json(),
  nodeResolve({
    main: true,
    module: true,
    jsnext: true,
    browser: true
  }),
  commonjs({
    include: [
      'node_modules/**'
    ],
    exclude: [
      'node_modules/process-es6/**'
    ],
    namedExports: {
      'node_modules/react/react.js': ['Children', 'Component', 'PropTypes', 'createElement'],
      'node_modules/react-dom/index.js': ['render', 'findDOMNode'],
      'node_modules/react-redux/es/index.js': ['default'],
      'node_modules/redux/es/index.js': ['default'],
      'node_modules/validator/index.js': ['isEmail', 'isNumeric', 'isLength']
    }
  }),
  buble({
    objectAssign: 'Object.assign'
  }),
  globals()
];

In my app code when I log process.env it has no properties. I would expect to see the MY_PROP prop which I'm setting in my config, along with all the other props on process.env

Am I missing some setup?

@calvinmetcalf
Copy link
Owner

we don't populate that object currently, you actually don't want to do what you suggested by default, or really ever, because there is a lot of stuff in your env and some of it you'd really not want to have bundled up in your client side code. it might make sense to add this as an option though to list the properties you want to include from the env.

@blockscoped
Copy link
Author

Yeah, that makes sense. There's a lot of junk on the node process.env that doesn't need to be copied. But I think the idea of and include option is a good one. Probably an array of prop names that you'd like clone.

Something like:

globals({
    include: [
        process: [
            env: ['MY_PROP', 'MY_OTHER_PROP']
        ]
    ]
})

@jedahan
Copy link

jedahan commented Mar 15, 2018

Is there a way for the umd to check if it is being required from the commandline, and then proxy the process object?

@calvinmetcalf
Copy link
Owner

if this is running in node...you don't need this library because node provides it all

@jedahan
Copy link

jedahan commented Mar 16, 2018

@calvinmetcalf if I am using rollup to create a single UMD, don't I need this in case its loaded by the browser?

@calvinmetcalf
Copy link
Owner

this is based on how browserify and webpack do it, but they assume their bundles will only be used in a browser, so you may just want to build 2 bundles, one that includes this for the browser and one that doesn't for the server

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

3 participants