vite/playground/optimize-deps/cjs.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

2020-12-27 05:47:18 +00:00
// test importing both default and named exports from a CommonJS module
// React is the ultimate test of this because its dynamic exports assignments
// are not statically detectable by @rollup/plugin-commonjs.
import React, { useState } from 'react'
2022-06-15 12:54:40 +00:00
import ReactDOM from 'react-dom/client'
import { Socket } from 'phoenix'
import clip from 'clipboard'
// Test exporting a name that was already imported
export { useState } from 'react'
export { useState as anotherNameForUseState } from 'react'
export { default as React } from 'react'
if (typeof clip === 'function') {
2021-06-24 12:28:25 +00:00
text('.cjs-clipboard', 'ok')
}
if (typeof Socket === 'function') {
2021-06-24 12:28:25 +00:00
text('.cjs-phoenix', 'ok')
}
2020-12-27 05:47:18 +00:00
function App() {
const [count, setCount] = useState(0)
return React.createElement(
'button',
{
onClick() {
setCount(count + 1)
},
},
`count is ${count}`,
)
}
2022-06-15 12:54:40 +00:00
ReactDOM.createRoot(document.querySelector('.cjs')).render(
React.createElement(App),
)
2021-06-24 12:28:25 +00:00
function text(el, text) {
document.querySelector(el).textContent = text
}