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

Support process.env.npm_package_version Inlining #8470

Open
graphemecluster opened this issue Sep 13, 2022 · 3 comments
Open

Support process.env.npm_package_version Inlining #8470

graphemecluster opened this issue Sep 13, 2022 · 3 comments

Comments

@graphemecluster
Copy link

…because Node already supports it.

Currently it seems that there are no way to include the version field in package.json without prepending cross-env NPM_PACKAGE_VERSION=$npm_package_version to the parcel commands. That's verbose, and requires cross-env to be installed.

Of course you might say, I could just import the JSON file directly by import { version } from "../package.json". But that requires manually turning resolveJsonModule on. Moreover, this will including the whole JSON file, exposing other useless information in the bundle. I hate importing things outside src either.

Some people might want npm_package_name and npm_package_description too.

@panstav
Copy link

panstav commented Oct 22, 2022

According to the docs, you can add this to your package.json:

"@parcel/transformer-js": {
    "inlineEnvironment": ["npm_package_version"]
}

@LeoDog896
Copy link
Contributor

LeoDog896 commented Feb 2, 2023

I do think that in the spirit of node emulation, all node_package_ variables should be inlined. (NPM Docs)

tomchen added a commit to tomchen/peerjs that referenced this issue Mar 1, 2025
Using parcel's `inlineEnvironment` parcel-bundler/parcel#8470 (comment) to inline the version so the whole package.json content is not included in the bundle

Must use `"context": "browser"` for targets.main and targets.module, default context "node" can't inline `process.env.npm_package_version`

Added @types/node for `process`'s type definition

Closes peers#1322
@tomchen
Copy link

tomchen commented Mar 1, 2025

According to the docs, you can add this to your package.json:

"@parcel/transformer-js": {
    "inlineEnvironment": ["npm_package_version"]
}

Not only this, but user has to use "context": "browser" in targets like I just did in the commit to peerjs that's mentioned above - default context "node" can't inline process.env.npm_package_version

But why with context "node" it doesn't inline process.env.npm_package_version? if @parcel/transformer-js.inlineEnvironment sets it explicitly, it should inline it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants