forked from vitejs/vite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate plugin-react-refresh to plugin-react
See vitejs#3588 for full commit history Co-authored-by: Shinigami <[email protected]> Co-authored-by: Peng Xiao <[email protected]>
- Loading branch information
1 parent
86a8a13
commit 9b3259d
Showing
29 changed files
with
2,916 additions
and
2,051 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
const reactRefresh = require('@vitejs/plugin-react-refresh') | ||
const react = require('@vitejs/plugin-react') | ||
|
||
/** | ||
* @type {import('vite').UserConfig} | ||
*/ | ||
module.exports = { | ||
plugins: [reactRefresh()], | ||
plugins: [react()], | ||
build: { | ||
// to make tests faster | ||
minify: false | ||
}, | ||
esbuild: { | ||
jsxInject: `import React from 'react'` | ||
} | ||
} |
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,56 @@ | ||
import { useState } from 'react' | ||
import { css } from '@emotion/react' | ||
|
||
import _Switch from 'react-switch' | ||
const Switch = _Switch.default || _Switch; | ||
|
||
export function Counter() { | ||
const [count, setCount] = useState(0) | ||
|
||
return ( | ||
<button | ||
css={css` | ||
border: 2px solid #000; | ||
`} | ||
onClick={() => setCount((count) => count + 1)} | ||
> | ||
count is: {count} | ||
</button> | ||
) | ||
} | ||
|
||
function FragmentTest() { | ||
const [checked, setChecked] = useState(false) | ||
return ( | ||
<> | ||
<Switch checked={checked} onChange={setChecked} /> | ||
<p> | ||
<Counter /> | ||
</p> | ||
</> | ||
) | ||
} | ||
|
||
function App() { | ||
return ( | ||
<div className="App"> | ||
<header className="App-header"> | ||
<h1>Hello Vite + React + @emotion/react</h1> | ||
<FragmentTest /> | ||
<p> | ||
Edit <code>App.jsx</code> and save to test HMR updates. | ||
</p> | ||
<a | ||
className="App-link" | ||
href="https://reactjs.org" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
Learn React | ||
</a> | ||
</header> | ||
</div> | ||
) | ||
} | ||
|
||
export default App |
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,45 @@ | ||
import { editFile, untilUpdated } from '../../testUtils' | ||
|
||
test('should render', async () => { | ||
expect(await page.textContent('h1')).toMatch( | ||
'Hello Vite + React + @emotion/react' | ||
) | ||
}) | ||
|
||
test('should update', async () => { | ||
expect(await page.textContent('button')).toMatch('count is: 0') | ||
await page.click('button') | ||
expect(await page.textContent('button')).toMatch('count is: 1') | ||
}) | ||
|
||
test('should hmr', async () => { | ||
editFile('App.jsx', (code) => | ||
code.replace('Vite + React + @emotion/react', 'Updated') | ||
) | ||
await untilUpdated(() => page.textContent('h1'), 'Hello Updated') | ||
// preserve state | ||
expect(await page.textContent('button')).toMatch('count is: 1') | ||
}) | ||
|
||
test('should update button style', async () => { | ||
function getButtonBorderStyle() { | ||
return page.evaluate(() => { | ||
return window.getComputedStyle(document.querySelector('button')).border | ||
}) | ||
} | ||
|
||
const styles = await page.evaluate(() => { | ||
return document.querySelector('button').style | ||
}) | ||
|
||
expect(await getButtonBorderStyle()).toMatch('2px solid rgb(0, 0, 0)') | ||
|
||
editFile('App.jsx', (code) => | ||
code.replace('border: 2px solid #000', 'border: 4px solid red') | ||
) | ||
|
||
await untilUpdated(getButtonBorderStyle, '4px solid rgb(255, 0, 0)') | ||
|
||
// preserve state | ||
expect(await page.textContent('button')).toMatch('count is: 1') | ||
}) |
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,8 @@ | ||
<div id="app"></div> | ||
<script type="module"> | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import App from './App.jsx' | ||
|
||
ReactDOM.render(React.createElement(App), document.getElementById('app')) | ||
</script> |
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,27 @@ | ||
{ | ||
"name": "test-react-emotion", | ||
"private": true, | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"debug": "node --inspect-brk ../../vite/bin/vite", | ||
"serve": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@emotion/react": "^11.4.0", | ||
"react": "^17.0.1", | ||
"react-dom": "^17.0.1", | ||
"react-switch": "^6.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/plugin-proposal-pipeline-operator": "^7.14.5", | ||
"@emotion/babel-plugin": "^11.3.0", | ||
"@vitejs/plugin-react": "^1.0.0" | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"@babel/preset-env" | ||
] | ||
} | ||
} |
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,19 @@ | ||
import react from '@vitejs/plugin-react' | ||
|
||
const config: import('vite').UserConfig = { | ||
plugins: [ | ||
react({ | ||
jsxImportSource: '@emotion/react', | ||
babel: { | ||
plugins: ['@emotion/babel-plugin'] | ||
} | ||
}) | ||
], | ||
clearScreen: false, | ||
build: { | ||
// to make tests faster | ||
minify: false | ||
} | ||
} | ||
|
||
export default config |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import react from '@vitejs/plugin-react' | ||
|
||
const config: import('vite').UserConfig = { | ||
plugins: [react()], | ||
build: { | ||
// to make tests faster | ||
minify: false | ||
} | ||
} | ||
|
||
export default config |
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
Oops, something went wrong.