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

feat: replace %SNOWPACK_PUBLIC_*% and %MODE% environment variables in HTML #900

Merged
merged 9 commits into from
Aug 26, 2020
Merged

feat: replace %SNOWPACK_PUBLIC_*% and %MODE% environment variables in HTML #900

merged 9 commits into from
Aug 26, 2020

Conversation

gr2m
Copy link
Contributor

@gr2m gr2m commented Aug 24, 2020

fixes #898 /cc @silverwind @FredKSchott

Changes

  • add test for replacing environment variables in HTML
  • implement replacing environment variables in HTML

Testing

  • added new test to test/build/

@vercel
Copy link

vercel bot commented Aug 24, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/9nudk1pya
✅ Preview: https://snowpack-git-fork-gr2m-898-env-variables-in-html.pikapkg.vercel.app

@gr2m gr2m marked this pull request as ready for review August 24, 2020 21:47
@gr2m gr2m requested a review from a team as a code owner August 24, 2020 21:47
Copy link
Owner

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

Can we add/clarify the docs at https://www.snowpack.dev/#environment-variables in this PR as well?

snowpack/src/build/build-import-proxy.ts Show resolved Hide resolved
snowpack/src/build/build-import-proxy.ts Outdated Show resolved Hide resolved
snowpack/src/build/build-import-proxy.ts Show resolved Hide resolved
Copy link
Contributor Author

@gr2m gr2m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all set

@@ -197,7 +197,7 @@ export async function buildFile(
): Promise<SnowpackBuildMap> {
// Pass 1: Find the first plugin to load this file, and return the result
const loadResult = await runPipelineLoadStep(srcPath, buildFileOptions);
// Pass 2: Pass that result through every plugin transfomr() method.
// Pass 2: Pass that result through every plugin transform() method.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

hmr: false,
config: this.config,
mode: 'production',
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add the mode option to differentiate between the build & dev commands

Copy link
Owner

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

return `export default ${JSON.stringify(envObject)};`;
}

const PUBLIC_ENV_REGEX = /^SNOWPACK_PUBLIC_/;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be /^SNOWPACK_PUBLIC_.*/ so it doesn't match a SNOWPACK_PUBLIC_ variable?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, good catch. I think that that's worth adding. technically it should be /^SNOWPACK_PUBLIC_.+/, since * can match 0 items.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, /^SNOWPACK_PUBLIC_.+/ is what I meant 😉

Copy link
Contributor Author

@gr2m gr2m Aug 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make I made a follow up issue so we can ship this change: #924

@gr2m gr2m changed the title 898/env variables in html feat: replace %SNOWPACK_PUBLIC_*% and %MODE% environment variables in HTML Aug 26, 2020
@gr2m gr2m merged commit 221c26f into FredKSchott:master Aug 26, 2020
@gr2m gr2m deleted the 898/env-variables-in-html branch August 26, 2020 16:35
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.

Support custom env variables in HTML
4 participants