Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

Commit

Permalink
Set up repo with optimizeDep problem
Browse files Browse the repository at this point in the history
  • Loading branch information
eddeee888 committed Jul 17, 2021
1 parent 74543a2 commit 3cb8ace
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 77 deletions.
5 changes: 3 additions & 2 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "demo",
"private": true,
"scripts": {
"dev": "vite",
"dev": "vite --force",
"build": "vite build",
"test": "sirv dist"
},
Expand All @@ -20,6 +20,7 @@
"@vitejs/plugin-react-refresh": "^1.3.3",
"sirv-cli": "^1.0.8",
"vite": "link:../node_modules/vite",
"vite-react-jsx": "link:.."
"vite-react-jsx": "link:..",
"vite-tsconfig-paths": "^3.3.13"
}
}
70 changes: 70 additions & 0 deletions demo/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 4 additions & 51 deletions demo/src/Root.tsx
Original file line number Diff line number Diff line change
@@ -1,54 +1,7 @@
import { useState } from 'react'

// This local package uses the automatic JSX runtime in a .jsx module
import One from 'react-one'

// This local package uses `import React from 'react'` in a .tsx module
import Two from 'react-two'

// This package has a minified CJS entry point and a development module
import { Switch } from './deps'

// This package has a ESM entry point
import Dropzone from 'react-dropzone'
// PROBLEM: This is an alias path set in tsconfig.json
// This points to src/shared/ui which has an index.ts file that exports stuff
import { File } from '@/shared/ui'

export const Root = () => {
const [checked, setChecked] = useState(false)
return (
<>
<One />
<Two />
<Switch checked={checked} onChange={setChecked} />
<FileZone />
</>
)
return <File />
}

const FileZone = () => (
<div style={{ width: 200, margin: '50px auto' }}>
<Dropzone>
{state => (
<div {...state.getRootProps()}>
<input {...state.getInputProps()} />
<div
style={{
width: 200,
height: 200,
borderRadius: 10,
background: `hsla(0, 0%, 100%, ${
state.isDragActive ? 0.3 : 0.1
})`,
color: 'white',
fontSize: 14,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
userSelect: 'none',
}}>
Drop a file on me!
</div>
</div>
)}
</Dropzone>
</div>
)
3 changes: 3 additions & 0 deletions demo/src/shared/ui/File/File.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// import React from 'react'

export const File = () => <div>File</div>
1 change: 1 addition & 0 deletions demo/src/shared/ui/File/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './File'
1 change: 1 addition & 0 deletions demo/src/shared/ui/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './File'
37 changes: 33 additions & 4 deletions demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
{
"extends": "../tsconfig.json",
"include": ["src", "vite.config.ts"],
"compilerOptions": {
"rootDir": ".",
"baseUrl": ".",
"target": "ESNext",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"module": "ESNext",
"moduleResolution": "Node",
"jsx": "react-jsx",
"lib": ["dom", "es2018"]
}
"noEmit": true,
"alwaysStrict": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"removeComments": true,
"preserveConstEnums": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"noImplicitAny": true,
"esModuleInterop": false,
"declaration": true,
"allowJs": false,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noUnusedLocals": true,
"downlevelIteration": true,
"noFallthroughCasesInSwitch": true,
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["./src"],
"exclude": ["node_modules"]
}
13 changes: 7 additions & 6 deletions demo/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import reactJsx from 'vite-react-jsx'
import reactRefresh from '@vitejs/plugin-react-refresh'
import tsconfigPaths from 'vite-tsconfig-paths'
import type { UserConfig } from 'vite'

const config: UserConfig = {
plugins: [reactRefresh(), reactJsx()],
build: {
// The minified bundle works as expected.
minify: false,
// Source maps are generated properly.
sourcemap: true,
plugins: [reactRefresh(), tsconfigPaths(), reactJsx()],
// PROBLEM: Current setup does not work with `optimizeDeps`
// It will say something like this in the browser console:
// File.tsx:3 Uncaught ReferenceError: React is not defined
optimizeDeps: {
include: ['@/shared/ui'],
},
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@types/resolve": "^1.20.0",
"prettier": "^2.0.5",
"typescript": "^4.0.0",
"vite": "latest"
"vite": "2.4.2"
},
"prettier": "@alloc/prettier-config",
"keywords": [
Expand Down
26 changes: 13 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3cb8ace

Please sign in to comment.