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

Commit 3cb8ace

Browse files
committed
Set up repo with optimizeDep problem
1 parent 74543a2 commit 3cb8ace

10 files changed

Lines changed: 136 additions & 77 deletions

File tree

demo/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "demo",
33
"private": true,
44
"scripts": {
5-
"dev": "vite",
5+
"dev": "vite --force",
66
"build": "vite build",
77
"test": "sirv dist"
88
},
@@ -20,6 +20,7 @@
2020
"@vitejs/plugin-react-refresh": "^1.3.3",
2121
"sirv-cli": "^1.0.8",
2222
"vite": "link:../node_modules/vite",
23-
"vite-react-jsx": "link:.."
23+
"vite-react-jsx": "link:..",
24+
"vite-tsconfig-paths": "^3.3.13"
2425
}
2526
}

demo/pnpm-lock.yaml

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/src/Root.tsx

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,7 @@
1-
import { useState } from 'react'
2-
3-
// This local package uses the automatic JSX runtime in a .jsx module
4-
import One from 'react-one'
5-
6-
// This local package uses `import React from 'react'` in a .tsx module
7-
import Two from 'react-two'
8-
9-
// This package has a minified CJS entry point and a development module
10-
import { Switch } from './deps'
11-
12-
// This package has a ESM entry point
13-
import Dropzone from 'react-dropzone'
1+
// PROBLEM: This is an alias path set in tsconfig.json
2+
// This points to src/shared/ui which has an index.ts file that exports stuff
3+
import { File } from '@/shared/ui'
144

155
export const Root = () => {
16-
const [checked, setChecked] = useState(false)
17-
return (
18-
<>
19-
<One />
20-
<Two />
21-
<Switch checked={checked} onChange={setChecked} />
22-
<FileZone />
23-
</>
24-
)
6+
return <File />
257
}
26-
27-
const FileZone = () => (
28-
<div style={{ width: 200, margin: '50px auto' }}>
29-
<Dropzone>
30-
{state => (
31-
<div {...state.getRootProps()}>
32-
<input {...state.getInputProps()} />
33-
<div
34-
style={{
35-
width: 200,
36-
height: 200,
37-
borderRadius: 10,
38-
background: `hsla(0, 0%, 100%, ${
39-
state.isDragActive ? 0.3 : 0.1
40-
})`,
41-
color: 'white',
42-
fontSize: 14,
43-
display: 'flex',
44-
alignItems: 'center',
45-
justifyContent: 'center',
46-
userSelect: 'none',
47-
}}>
48-
Drop a file on me!
49-
</div>
50-
</div>
51-
)}
52-
</Dropzone>
53-
</div>
54-
)

demo/src/shared/ui/File/File.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// import React from 'react'
2+
3+
export const File = () => <div>File</div>

demo/src/shared/ui/File/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './File'

demo/src/shared/ui/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './File'

demo/tsconfig.json

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
11
{
2-
"extends": "../tsconfig.json",
3-
"include": ["src", "vite.config.ts"],
42
"compilerOptions": {
3+
"rootDir": ".",
4+
"baseUrl": ".",
5+
"target": "ESNext",
6+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
7+
"module": "ESNext",
8+
"moduleResolution": "Node",
59
"jsx": "react-jsx",
6-
"lib": ["dom", "es2018"]
7-
}
10+
"noEmit": true,
11+
"alwaysStrict": true,
12+
"noImplicitThis": true,
13+
"noImplicitReturns": true,
14+
"removeComments": true,
15+
"preserveConstEnums": true,
16+
"strictFunctionTypes": true,
17+
"strictNullChecks": true,
18+
"noImplicitAny": true,
19+
"esModuleInterop": false,
20+
"declaration": true,
21+
"allowJs": false,
22+
"skipLibCheck": true,
23+
"allowSyntheticDefaultImports": true,
24+
"strict": true,
25+
"forceConsistentCasingInFileNames": true,
26+
"resolveJsonModule": true,
27+
"isolatedModules": true,
28+
"noUnusedLocals": true,
29+
"downlevelIteration": true,
30+
"noFallthroughCasesInSwitch": true,
31+
"paths": {
32+
"@/*": ["./src/*"]
33+
}
34+
},
35+
"include": ["./src"],
36+
"exclude": ["node_modules"]
837
}

demo/vite.config.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import reactJsx from 'vite-react-jsx'
22
import reactRefresh from '@vitejs/plugin-react-refresh'
3+
import tsconfigPaths from 'vite-tsconfig-paths'
34
import type { UserConfig } from 'vite'
45

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@types/resolve": "^1.20.0",
3131
"prettier": "^2.0.5",
3232
"typescript": "^4.0.0",
33-
"vite": "latest"
33+
"vite": "2.4.2"
3434
},
3535
"prettier": "@alloc/prettier-config",
3636
"keywords": [

pnpm-lock.yaml

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)