-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): support reload .env files and restart dev server (#767)
- Loading branch information
1 parent
da80608
commit 49d9457
Showing
13 changed files
with
98 additions
and
27 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,5 @@ | ||
--- | ||
'@rsbuild/core': patch | ||
--- | ||
|
||
feat(cli): support reload .env files and restart dev server |
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.
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 @@ | ||
rsbuild.config.mjs |
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,44 @@ | ||
import path from 'path'; | ||
import { exec } from 'child_process'; | ||
import { test, expect } from '@playwright/test'; | ||
import { fse } from '@rsbuild/shared'; | ||
import { awaitFileExists } from '@scripts/helper'; | ||
import { getRandomPort } from '@scripts/shared'; | ||
|
||
test('should restart dev server when .env file is changed', async () => { | ||
const dist = path.join(__dirname, 'dist'); | ||
const configFile = path.join(__dirname, 'rsbuild.config.mjs'); | ||
const envLocalFile = path.join(__dirname, '.env.local'); | ||
const distIndex = path.join(dist, 'static/js/index.js'); | ||
fse.removeSync(dist); | ||
fse.removeSync(configFile); | ||
fse.removeSync(envLocalFile); | ||
|
||
fse.writeFileSync(envLocalFile, ``); | ||
fse.writeFileSync( | ||
configFile, | ||
`export default { | ||
output: { | ||
distPath: { | ||
root: 'dist', | ||
}, | ||
disableFilenameHash: true, | ||
}, | ||
server: { port: ${getRandomPort()} } | ||
};`, | ||
); | ||
|
||
const process = exec('npx rsbuild dev', { | ||
cwd: __dirname, | ||
}); | ||
|
||
await awaitFileExists(distIndex); | ||
expect(fse.readFileSync(distIndex, 'utf-8')).not.toContain('jack'); | ||
fse.removeSync(distIndex); | ||
|
||
fse.writeFileSync(envLocalFile, `PUBLIC_NAME=jack`); | ||
await awaitFileExists(distIndex); | ||
expect(fse.readFileSync(distIndex, 'utf-8')).toContain('jack'); | ||
|
||
process.kill(); | ||
}); |
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 @@ | ||
console.log('hello!', process.env.PUBLIC_NAME); |
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,12 @@ | ||
{ | ||
"extends": "@rsbuild/tsconfig/base", | ||
"compilerOptions": { | ||
"jsx": "react-jsx", | ||
"baseUrl": "./", | ||
"outDir": "./dist", | ||
"paths": { | ||
"@scripts/*": ["../../../scripts/*"] | ||
} | ||
}, | ||
"include": ["src", "*.test.ts"] | ||
} |
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