3bfdc2c83f
## Summary
Continues the Emotion → Linaria migration (PR 4-6 from the [migration
plan](docs/emotion-to-linaria-migration-plan.md)). Migrates **311
files** across four module groups:
| Module | Files |
|---|---|
| command-menu | 53 |
| workflow | 84 |
| page-layout | 84 |
| UI (partial - first ~80 files) | ~80 |
| twenty-ui (TEXT_INPUT_STYLE) | 1 |
| misc (hooks, keyboard-shortcut-menu, file-upload) | ~9 |
### Migration patterns applied
- `import styled from '@emotion/styled'` → `import { styled } from
'@linaria/react'`
- `import { useTheme } from '@emotion/react'` → `import { useContext }
from 'react'` + `import { ThemeContext } from 'twenty-ui/theme'`
- `${({ theme }) => theme.X.Y.Z}` → `${themeCssVariables.X.Y.Z}` (static
CSS variables)
- `theme.spacing(N)` → `themeCssVariables.spacing[N]`
- `styled(motion.div)` → `motion.create(StyledBase)` (11 components)
- `styled(Component)<TypeParams>` → wrapper div approach for non-HTML
elements
- Multi-declaration interpolations split into one CSS property per
interpolation
- Interpolation return types fixed (`&&` → ternary `? : ''`)
- `TEXT_INPUT_STYLE` converted from function to static string constant
(backward compatible)
- Emotion `<Global>` replaced with `useEffect` style injection
- Complex runtime-dependent styles use CSS custom properties via
`style={}` prop
### After this PR
- **Remaining files**: ~400 (object-record: ~160, settings: ~200, UI:
~44)
- **No breaking changes**: CSS variables resolve identically to the
previous Emotion theme values
141 lines
3.7 KiB
TypeScript
141 lines
3.7 KiB
TypeScript
import react from '@vitejs/plugin-react-swc';
|
|
import wyw from '@wyw-in-js/vite';
|
|
import * as path from 'path';
|
|
import { defineConfig } from 'vite';
|
|
import checker from 'vite-plugin-checker';
|
|
import dts, { type PluginOptions } from 'vite-plugin-dts';
|
|
import svgr from 'vite-plugin-svgr';
|
|
import tsconfigPaths from 'vite-tsconfig-paths';
|
|
|
|
type Checkers = Parameters<typeof checker>[0];
|
|
|
|
import packageJson from './package.json';
|
|
|
|
const entries = Object.keys(packageJson.exports)
|
|
.filter((el) => el !== './style.css')
|
|
.map((module) => `src/${module}/index.ts`);
|
|
|
|
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}`,
|
|
);
|
|
}
|
|
|
|
const moduleDirectory = splitFaceModuleId[splitFaceModuleId?.length - 2];
|
|
if (moduleDirectory === 'src') {
|
|
return `${chunk.name}.${extension}`;
|
|
}
|
|
return `${moduleDirectory}.${extension}`;
|
|
};
|
|
|
|
export default defineConfig(({ command }) => {
|
|
const isBuildCommand = command === 'build';
|
|
|
|
const tsConfigPath = isBuildCommand
|
|
? path.resolve(__dirname, './tsconfig.lib.json')
|
|
: path.resolve(__dirname, './tsconfig.json');
|
|
|
|
const checkersConfig: Checkers = {
|
|
typescript: {
|
|
tsconfigPath: tsConfigPath,
|
|
},
|
|
};
|
|
|
|
const dtsConfig: PluginOptions = {
|
|
entryRoot: 'src',
|
|
tsconfigPath: tsConfigPath,
|
|
};
|
|
|
|
return {
|
|
resolve: {
|
|
alias: {
|
|
'@ui/': path.resolve(__dirname, 'src') + '/',
|
|
'@assets/': path.resolve(__dirname, 'src/assets') + '/',
|
|
},
|
|
},
|
|
css: {
|
|
modules: {
|
|
localsConvention: 'camelCaseOnly',
|
|
},
|
|
},
|
|
optimizeDeps: {
|
|
exclude: ['../../node_modules/.vite', '../../node_modules/.cache'],
|
|
},
|
|
root: __dirname,
|
|
cacheDir: '../../node_modules/.vite/packages/twenty-ui',
|
|
assetsInclude: ['src/**/*.svg'],
|
|
plugins: [
|
|
react(),
|
|
tsconfigPaths({
|
|
root: __dirname,
|
|
projects: ['tsconfig.json'],
|
|
}),
|
|
svgr(),
|
|
dts(dtsConfig),
|
|
checker(checkersConfig),
|
|
{
|
|
...wyw({
|
|
include: [path.resolve(__dirname, 'src') + '/**/*.{ts,tsx}'],
|
|
babelOptions: {
|
|
presets: ['@babel/preset-typescript', '@babel/preset-react'],
|
|
},
|
|
}),
|
|
enforce: 'pre',
|
|
},
|
|
],
|
|
build: {
|
|
cssCodeSplit: false,
|
|
minify: 'esbuild',
|
|
sourcemap: false,
|
|
emptyOutDir: false,
|
|
outDir: './dist',
|
|
reportCompressedSize: true,
|
|
commonjsOptions: {
|
|
transformMixedEsModules: true,
|
|
interopDefault: true,
|
|
defaultIsModuleExports: true,
|
|
requireReturnsDefault: 'auto',
|
|
},
|
|
lib: {
|
|
entry: ['src/index.ts', ...entries],
|
|
name: 'twenty-ui',
|
|
},
|
|
rollupOptions: {
|
|
external: Object.keys(packageJson.dependencies || {}),
|
|
output: [
|
|
{
|
|
assetFileNames: 'style.css',
|
|
globals: {
|
|
react: 'React',
|
|
'react-dom': 'ReactDOM',
|
|
},
|
|
format: 'es',
|
|
entryFileNames: (chunk) => entryFileNames(chunk, 'mjs'),
|
|
},
|
|
{
|
|
assetFileNames: 'style.css',
|
|
format: 'cjs',
|
|
globals: {
|
|
react: 'React',
|
|
'react-dom': 'ReactDOM',
|
|
},
|
|
interop: 'auto',
|
|
esModule: true,
|
|
exports: 'named',
|
|
entryFileNames: (chunk) => entryFileNames(chunk, 'cjs'),
|
|
},
|
|
],
|
|
},
|
|
},
|
|
logLevel: 'error',
|
|
};
|
|
});
|