-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: define
import.meta.env.BASE_URL
(#3632)
- Loading branch information
1 parent
dbab19e
commit 2fedf37
Showing
17 changed files
with
153 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { build, dev, rspackOnlyTest } from '@e2e/helper'; | ||
import { expect } from '@playwright/test'; | ||
|
||
rspackOnlyTest( | ||
'should define BASE_URL env var correctly in dev', | ||
async ({ page }) => { | ||
const rsbuild = await dev({ | ||
cwd: __dirname, | ||
page, | ||
rsbuildConfig: { | ||
html: { | ||
template: './src/index.html', | ||
}, | ||
server: { | ||
base: '/base', | ||
}, | ||
}, | ||
}); | ||
|
||
// should define `process.env.BASE_URL` correctly | ||
await expect(page.locator('#public-base-path-process')).toHaveText('/base'); | ||
|
||
// should define `import.meta.env.BASE_URL` correctly | ||
await expect(page.locator('#public-base-path-meta')).toHaveText('/base'); | ||
|
||
await rsbuild.close(); | ||
}, | ||
); | ||
|
||
rspackOnlyTest( | ||
'should define BASE_URL env var correctly in build', | ||
async ({ page }) => { | ||
const rsbuild = await build({ | ||
cwd: __dirname, | ||
page, | ||
rsbuildConfig: { | ||
html: { | ||
template: './src/index.html', | ||
}, | ||
server: { | ||
base: '/base', | ||
}, | ||
}, | ||
}); | ||
|
||
// should define `process.env.BASE_URL` correctly | ||
await expect(page.locator('#public-base-path-process')).toHaveText('/base'); | ||
|
||
// should define `import.meta.env.BASE_URL` correctly | ||
await expect(page.locator('#public-base-path-meta')).toHaveText('/base'); | ||
|
||
await rsbuild.close(); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!doctype html> | ||
<html> | ||
<head></head> | ||
|
||
<body> | ||
<div id="public-base-path-process"><%= process.env.BASE_URL %></div> | ||
<div id="public-base-path-meta"><%= import.meta.env.BASE_URL %></div> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const testEl = document.createElement('div'); | ||
testEl.id = 'test'; | ||
testEl.innerHTML = 'Hello Rsbuild!'; | ||
|
||
document.body.appendChild(testEl); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters