-
Notifications
You must be signed in to change notification settings - Fork 5.7k
[create-twenty-app] Use vite config lib
#16273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,26 @@ | ||
| { | ||
| "extends": "../../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "outDir": "./dist", | ||
| "rootDir": "./src", | ||
| "target": "es2022", | ||
| "module": "commonjs", | ||
| "moduleResolution": "node", | ||
| "strict": true, | ||
| "esModuleInterop": true, | ||
| "allowJs": false, | ||
| "esModuleInterop": false, | ||
| "allowSyntheticDefaultImports": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "skipLibCheck": true, | ||
| "resolveJsonModule": true, | ||
| "declaration": false, | ||
| "sourceMap": true | ||
| "strictNullChecks": true, | ||
| "alwaysStrict": true, | ||
| "noImplicitAny": true, | ||
| "strictBindCallApply": false, | ||
| "noEmit": true, | ||
| "paths": { | ||
| "@/*": ["./src/*"] | ||
| } | ||
| }, | ||
| "include": ["src"], | ||
| "exclude": [ | ||
| "node_modules", | ||
| "dist", | ||
| "**/*.test.ts", | ||
| "**/*.spec.ts", | ||
| "**/__tests__/**" | ||
| ] | ||
| "files": [], | ||
| "include": [], | ||
| "references": [ | ||
| { | ||
| "path": "./tsconfig.lib.json" | ||
| }, | ||
| { | ||
| "path": "./tsconfig.spec.json" | ||
| } | ||
| ], | ||
| "extends": "../../tsconfig.base.json" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "outDir": "./dist", | ||
| "rootDir": "./src", | ||
| "strict": true, | ||
| "esModuleInterop": true, | ||
| "allowSyntheticDefaultImports": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "skipLibCheck": true, | ||
| "resolveJsonModule": true, | ||
| "declaration": false, | ||
| "sourceMap": true | ||
| }, | ||
| "include": ["src"], | ||
| "exclude": [ | ||
| "node_modules", | ||
| "dist", | ||
| "**/*.test.ts", | ||
| "**/*.spec.ts", | ||
| "**/__tests__/**" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "types": ["jest", "node"] | ||
| }, | ||
| "include": [ | ||
| "**/__mocks__/**/*", | ||
| "jest.config.mjs", | ||
| "src/**/*.d.ts", | ||
| "src/**/*.spec.ts", | ||
| "src/**/*.spec.tsx", | ||
| "src/**/*.test.ts", | ||
| "src/**/*.test.tsx" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import fs from 'fs-extra'; | ||
| import path from 'path'; | ||
| import { defineConfig } from 'vite'; | ||
| import dts from 'vite-plugin-dts'; | ||
| import tsconfigPaths from 'vite-tsconfig-paths'; | ||
| import packageJson from './package.json'; | ||
|
|
||
| const moduleEntries = Object.keys((packageJson as any).exports || {}) | ||
| .filter( | ||
| (key) => key !== './style.css' && key !== '.' && !key.startsWith('./src/'), | ||
| ) | ||
| .map((module) => `src/${module.replace(/^\.\//, '')}/index.ts`); | ||
|
|
||
| const entries = ['src/cli.ts', ...moduleEntries]; | ||
|
|
||
| const entryFileNames = (chunk: any, extension: 'cjs' | 'mjs') => { | ||
| if (!chunk.isEntry) { | ||
| throw new Error( | ||
| `Should never occurs, encountered a non entry chunk ${chunk.facadeModuleId}`, | ||
| ); | ||
| } | ||
|
|
||
| const splitFaceModuleId = chunk.facadeModuleId?.split('/'); | ||
| if (splitFaceModuleId === undefined) { | ||
| throw new Error( | ||
| `Should never occurs splitFaceModuleId is undefined ${chunk.facadeModuleId}`, | ||
prastoin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
| } | ||
|
|
||
| const moduleDirectory = splitFaceModuleId[splitFaceModuleId?.length - 2]; | ||
| if (moduleDirectory === 'src') { | ||
| return `${chunk.name}.${extension}`; | ||
| } | ||
| return `${moduleDirectory}.${extension}`; | ||
| }; | ||
|
|
||
| export default defineConfig(() => { | ||
| const tsConfigPath = path.resolve(__dirname, './tsconfig.lib.json'); | ||
|
|
||
| return { | ||
| root: __dirname, | ||
| cacheDir: '../../node_modules/.vite/packages/create-twenty-app', | ||
| plugins: [ | ||
| tsconfigPaths({ | ||
| root: __dirname, | ||
| }), | ||
| dts({ entryRoot: './src', tsconfigPath: tsConfigPath }), | ||
| { | ||
| name: 'copy-assets', | ||
| closeBundle: async () => { | ||
| await fs.copy( | ||
| path.resolve(__dirname, 'src/constants/base-application'), | ||
| path.resolve(__dirname, 'dist/constants/base-application'), | ||
| ); | ||
| }, | ||
| }, | ||
| ], | ||
| build: { | ||
| outDir: 'dist', | ||
| lib: { entry: entries, name: 'create-twenty-app' }, | ||
| rollupOptions: { | ||
| external: [ | ||
| ...Object.keys((packageJson as any).dependencies || {}), | ||
| 'path', | ||
| 'fs', | ||
| 'child_process', | ||
| ], | ||
| output: [ | ||
| { | ||
| format: 'es', | ||
| entryFileNames: (chunk) => entryFileNames(chunk, 'mjs'), | ||
| }, | ||
|
Comment on lines
+68
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: ES module output 🔍 Detailed AnalysisThe 💡 Suggested FixConfigure Vite/Rollup to either polyfill 🤖 Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should use import.meta.dirname |
||
| { | ||
| format: 'cjs', | ||
| interop: 'auto', | ||
| esModule: true, | ||
| exports: 'named', | ||
| entryFileNames: (chunk) => entryFileNames(chunk, 'cjs'), | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| logLevel: 'warn', | ||
| }; | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.