Support PUBLIC_ environment variables (#1750)
* Support PUBLIC_ environment variables * Remove unnecessary Test component
This commit is contained in:
parent
a26f7a2088
commit
18172a6750
5 changed files with 29 additions and 0 deletions
|
@ -55,6 +55,7 @@ export async function createVite(inlineConfig: ViteConfigWithSSR, { astroConfig,
|
|||
],
|
||||
publicDir: fileURLToPath(astroConfig.public),
|
||||
root: fileURLToPath(astroConfig.projectRoot),
|
||||
envPrefix: 'PUBLIC_',
|
||||
server: {
|
||||
force: true, // force dependency rebuild (TODO: enabled only while next is unstable; eventually only call in "production" mode?)
|
||||
hmr: process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'production' ? false : undefined, // disable HMR for test
|
||||
|
|
23
packages/astro/test/astro-envs.test.js
Normal file
23
packages/astro/test/astro-envs.test.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { expect } from 'chai';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
|
||||
describe('Environment Variables', () => {
|
||||
let fixture;
|
||||
|
||||
before(async () => {
|
||||
fixture = await loadFixture({ projectRoot: './fixtures/astro-envs/' });
|
||||
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
it('builds without throwing', async () => {
|
||||
expect(true).to.equal(true);
|
||||
});
|
||||
|
||||
it('does render public env, does not render private env', async () => {
|
||||
let indexHtml = await fixture.readFile('/index.html');
|
||||
|
||||
expect(indexHtml).to.not.include('CLUB_33');
|
||||
expect(indexHtml).to.include('BLUE_BAYOU');
|
||||
});
|
||||
});
|
2
packages/astro/test/fixtures/astro-envs/.env
vendored
Normal file
2
packages/astro/test/fixtures/astro-envs/.env
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
SECRET_PLACE=CLUB_33
|
||||
PUBLIC_PLACE=BLUE_BAYOU
|
1
packages/astro/test/fixtures/astro-envs/.gitignore
vendored
Normal file
1
packages/astro/test/fixtures/astro-envs/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
!.env
|
2
packages/astro/test/fixtures/astro-envs/src/pages/index.astro
vendored
Normal file
2
packages/astro/test/fixtures/astro-envs/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
<environment-variable>{import.meta.env.PUBLIC_PLACE}</environment-variable>
|
||||
<environment-variable>{import.meta.env.SECRET_PLACE}</environment-variable>
|
Loading…
Reference in a new issue