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

frontend: narrow down DefinePlugin into EnvironmentPlugin #753

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wh0
Copy link
Contributor

@wh0 wh0 commented Mar 30, 2024

the previous DefinePlugin

new webpack.DefinePlugin({
    'process.env': JSON.stringify(process.env)
})

caused index.js

elasticsearchMappingSchemaVersion: parseInt(process.env.ELASTICSEARCH_MAPPING_SCHEMA_VERSION),
elasticsearchUrl: process.env.ELASTICSEARCH_URL || '/backend',
elasticsearchUsername : process.env.ELASTICSEARCH_USERNAME || ...,
elasticsearchPassword : process.env.ELASTICSEARCH_PASSWORD || ...,
nixosChannels : JSON.parse(process.env.NIXOS_CHANNELS)

to compile into

elasticsearchMappingSchemaVersion: parseInt('42'),
elasticsearchUrl: {
  NODE_ENV: 'production',
  SHELL: '/nix/store/0hx32wk55ml88jrb1qxwg5c5yazfm6gf-bash-5.2-p15/bin/bash',
  // the entire environment in JSON
}.ELASTICSEARCH_URL || '/backend',
elasticsearchUsername: {
  // the entire environment again
}.ELASTICSEARCH_USERNAME || ...,
elasticsearchPassword: {
  // again
}.ELASTICSEARCH_PASSWORD || ...,
nixosChannels: JSON.parse(...)

this removes it and puts the remaining used env vars in the existing EnvironmentPlugin:

new webpack.EnvironmentPlugin({
    ELASTICSEARCH_MAPPING_SCHEMA_VERSION: undefined,
    ELASTICSEARCH_URL: null,
    ELASTICSEARCH_USERNAME: null,
    ELASTICSEARCH_PASSWORD: null,
    NIXOS_CHANNELS: undefined
}),

(https://webpack.js.org/plugins/environment-plugin/#usage-with-default-values undefined for required, null for optional)

so that it now compiles into this less detailed code

elasticsearchMappingSchemaVersion: parseInt("42"),
elasticsearchUrl:  false || '/backend',
elasticsearchUsername:  false || ...,
elasticsearchPassword:  false || ...,
nixosChannels: JSON.parse(...)

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

Successfully merging this pull request may close these issues.

1 participant