@@ -8,10 +8,13 @@ import { readFileSync } from 'fs';
88
99const reactPkg = path . resolve ( __dirname , '../../packages/react/package.json' ) ;
1010const reactDir = path . resolve ( __dirname , '../../packages/react' ) ;
11+ const reactSrc = path . join ( reactDir , 'src' ) ;
1112const reactEs = path . join ( reactDir , 'es/index.js' ) ;
1213const iconsDir = path . resolve ( __dirname , '../../packages/icons' ) ;
14+ const iconsSrc = path . join ( iconsDir , 'src' ) ;
1315const iconsEs = path . join ( iconsDir , 'es/index.js' ) ;
1416const chartsDir = path . resolve ( __dirname , '../../packages/charts' ) ;
17+ const chartsSrc = path . join ( chartsDir , 'src' ) ;
1518const chartsEs = path . join ( chartsDir , 'es/index.js' ) ;
1619const tokensDir = path . resolve ( __dirname , '../../packages/tokens' ) ;
1720
@@ -29,119 +32,147 @@ function sanitizeChunkName(value: string): string {
2932 return value . replace ( / [ ^ a - z A - Z 0 - 9 _ - ] / g, '-' ) ;
3033}
3134
32- export default defineConfig ( {
33- base : process . env . VITE_BASE || '/' ,
34- define : {
35- __TINY_VERSION__ : JSON . stringify ( tinyVersion ) ,
36- } ,
37- plugins : [
38- { enforce : 'pre' , ...mdx ( {
39- mdxExtensions : [ '.mdx' , '.md' ] ,
40- mdExtensions : [ ] ,
41- providerImportSource : '@mdx-js/react' ,
42- remarkPlugins : [ remarkGfm ] ,
43- rehypePlugins : [ rehypeMdxCodeProps ] ,
44- } ) } ,
45- react ( { include : / \. ( j s x | t s x | m d | m d x ) $ / } ) ,
46- ] ,
47- resolve : {
48- alias : [
49- { find : / ^ @ t i n y - d e s i g n \/ r e a c t $ / , replacement : reactEs } ,
50- { find : / ^ @ t i n y - d e s i g n \/ r e a c t \/ ( .* ) $ / , replacement : path . join ( reactDir , 'es/$1' ) } ,
51- { find : / ^ @ t i n y - d e s i g n \/ i c o n s $ / , replacement : iconsEs } ,
52- { find : / ^ @ t i n y - d e s i g n \/ i c o n s \/ ( .* ) $ / , replacement : path . join ( iconsDir , 'es/$1' ) } ,
53- { find : / ^ @ t i n y - d e s i g n \/ c h a r t s $ / , replacement : chartsEs } ,
54- { find : / ^ @ t i n y - d e s i g n \/ c h a r t s \/ ( .* ) $ / , replacement : path . join ( chartsDir , 'es/$1' ) } ,
55- { find : '@tiny-design/tokens/registry-runtime' , replacement : path . join ( tokensDir , 'runtime/registry.mjs' ) } ,
56- { find : '@mdx-js/react' , replacement : path . resolve ( __dirname , 'node_modules/@mdx-js/react' ) } ,
35+ function createWorkspaceAliases ( mode : 'src' | 'es' ) {
36+ const useSource = mode === 'src' ;
37+
38+ return [
39+ {
40+ find : / ^ @ t i n y - d e s i g n \/ r e a c t $ / ,
41+ replacement : useSource ? reactSrc : reactEs ,
42+ } ,
43+ {
44+ find : / ^ @ t i n y - d e s i g n \/ r e a c t \/ ( .* ) $ / ,
45+ replacement : path . join ( reactDir , `${ useSource ? 'src' : 'es' } /$1` ) ,
46+ } ,
47+ {
48+ find : / ^ @ t i n y - d e s i g n \/ i c o n s $ / ,
49+ replacement : useSource ? iconsSrc : iconsEs ,
50+ } ,
51+ {
52+ find : / ^ @ t i n y - d e s i g n \/ i c o n s \/ ( .* ) $ / ,
53+ replacement : path . join ( iconsDir , `${ useSource ? 'src' : 'es' } /$1` ) ,
54+ } ,
55+ {
56+ find : / ^ @ t i n y - d e s i g n \/ c h a r t s $ / ,
57+ replacement : useSource ? chartsSrc : chartsEs ,
58+ } ,
59+ {
60+ find : / ^ @ t i n y - d e s i g n \/ c h a r t s \/ ( .* ) $ / ,
61+ replacement : path . join ( chartsDir , `${ useSource ? 'src' : 'es' } /$1` ) ,
62+ } ,
63+ { find : '@tiny-design/tokens/registry-runtime' , replacement : path . join ( tokensDir , 'runtime/registry.mjs' ) } ,
64+ { find : '@mdx-js/react' , replacement : path . resolve ( __dirname , 'node_modules/@mdx-js/react' ) } ,
65+ ] ;
66+ }
67+
68+ export default defineConfig ( ( { command } ) => {
69+ const aliasMode = command === 'serve' ? 'src' : 'es' ;
70+
71+ return {
72+ base : process . env . VITE_BASE || '/' ,
73+ define : {
74+ __TINY_VERSION__ : JSON . stringify ( tinyVersion ) ,
75+ } ,
76+ plugins : [
77+ { enforce : 'pre' , ...mdx ( {
78+ mdxExtensions : [ '.mdx' , '.md' ] ,
79+ mdExtensions : [ ] ,
80+ providerImportSource : '@mdx-js/react' ,
81+ remarkPlugins : [ remarkGfm ] ,
82+ rehypePlugins : [ rehypeMdxCodeProps ] ,
83+ } ) } ,
84+ react ( { include : / \. ( j s x | t s x | m d | m d x ) $ / } ) ,
5785 ] ,
58- dedupe : [ 'react' , 'react-dom' ] ,
59- } ,
60- server : {
61- port : 3000 ,
62- open : true ,
63- fs : {
64- allow : [ '../..' ] ,
86+ resolve : {
87+ alias : createWorkspaceAliases ( aliasMode ) ,
88+ dedupe : [ 'react' , 'react-dom' ] ,
6589 } ,
66- } ,
67- build : {
68- outDir : 'build' ,
69- chunkSizeWarningLimit : 750 ,
70- rollupOptions : {
71- output : {
72- manualChunks ( id ) {
73- if ( id . includes ( '/packages/react/es/' ) ) {
74- return 'tiny-react' ;
75- }
76-
77- if ( id . includes ( '/packages/icons/es/' ) ) {
78- return 'tiny-icons' ;
79- }
80-
81- if ( id . includes ( '/packages/charts/es/' ) ) {
82- return 'tiny-charts' ;
83- }
84-
85- if ( id . includes ( '/apps/docs/src/containers/home/' ) ) {
86- return 'docs-home' ;
87- }
88-
89- if ( ! id . includes ( 'node_modules' ) ) {
90- return undefined ;
91- }
92-
93- const packageName = getPackageName ( id ) ;
94-
95- if ( packageName && [ 'react' , 'react-dom' , 'scheduler' ] . includes ( packageName ) ) {
96- return 'vendor-react' ;
97- }
98-
99- if ( packageName && [ '@babel/runtime' , 'dom-helpers' ] . includes ( packageName ) ) {
100- return 'vendor-react' ;
101- }
102-
103- if (
104- packageName &&
105- (
106- packageName . startsWith ( '@mdx-js' ) ||
107- packageName . startsWith ( 'remark-' ) ||
108- packageName . startsWith ( 'rehype-' ) ||
109- [
110- 'unified' ,
111- 'micromark' ,
112- 'mdast-util-from-markdown' ,
113- 'mdast-util-mdx' ,
114- 'mdast-util-mdx-expression' ,
115- 'mdast-util-mdx-jsx' ,
116- 'mdast-util-mdxjs-esm' ,
117- 'mdast-util-to-hast' ,
118- 'hast-util-to-jsx-runtime' ,
119- 'hast-util-from-html' ,
120- 'vfile' ,
121- ] . includes ( packageName )
122- )
123- ) {
124- return 'vendor-mdx' ;
125- }
126-
127- if ( packageName && [ 'prism-react-renderer' , 'react-runner' ] . includes ( packageName ) ) {
128- return 'vendor-code' ;
129- }
130-
131- if ( packageName === 'recharts' || packageName === 'victory-vendor' ) {
132- return 'vendor-charts' ;
133- }
134-
135- return packageName ? `vendor-${ sanitizeChunkName ( packageName ) } ` : 'vendor' ;
90+ server : {
91+ port : 3000 ,
92+ open : true ,
93+ fs : {
94+ allow : [ '../..' ] ,
95+ } ,
96+ } ,
97+ build : {
98+ outDir : 'build' ,
99+ chunkSizeWarningLimit : 750 ,
100+ rollupOptions : {
101+ output : {
102+ manualChunks ( id ) {
103+ if ( id . includes ( '/packages/react/es/' ) ) {
104+ return 'tiny-react' ;
105+ }
106+
107+ if ( id . includes ( '/packages/icons/es/' ) ) {
108+ return 'tiny-icons' ;
109+ }
110+
111+ if ( id . includes ( '/packages/charts/es/' ) ) {
112+ return 'tiny-charts' ;
113+ }
114+
115+ if ( id . includes ( '/apps/docs/src/containers/home/' ) ) {
116+ return 'docs-home' ;
117+ }
118+
119+ if ( ! id . includes ( 'node_modules' ) ) {
120+ return undefined ;
121+ }
122+
123+ const packageName = getPackageName ( id ) ;
124+
125+ if ( packageName && [ 'react' , 'react-dom' , 'scheduler' ] . includes ( packageName ) ) {
126+ return 'vendor-react' ;
127+ }
128+
129+ if ( packageName && [ '@babel/runtime' , 'dom-helpers' ] . includes ( packageName ) ) {
130+ return 'vendor-react' ;
131+ }
132+
133+ if (
134+ packageName &&
135+ (
136+ packageName . startsWith ( '@mdx-js' ) ||
137+ packageName . startsWith ( 'remark-' ) ||
138+ packageName . startsWith ( 'rehype-' ) ||
139+ [
140+ 'unified' ,
141+ 'micromark' ,
142+ 'mdast-util-from-markdown' ,
143+ 'mdast-util-mdx' ,
144+ 'mdast-util-mdx-expression' ,
145+ 'mdast-util-mdx-jsx' ,
146+ 'mdast-util-mdxjs-esm' ,
147+ 'mdast-util-to-hast' ,
148+ 'hast-util-to-jsx-runtime' ,
149+ 'hast-util-from-html' ,
150+ 'vfile' ,
151+ ] . includes ( packageName )
152+ )
153+ ) {
154+ return 'vendor-mdx' ;
155+ }
156+
157+ if ( packageName && [ 'prism-react-renderer' , 'react-runner' ] . includes ( packageName ) ) {
158+ return 'vendor-code' ;
159+ }
160+
161+ if ( packageName === 'recharts' || packageName === 'victory-vendor' ) {
162+ return 'vendor-charts' ;
163+ }
164+
165+ return packageName ? `vendor-${ sanitizeChunkName ( packageName ) } ` : 'vendor' ;
166+ } ,
136167 } ,
137168 } ,
138169 } ,
139- } ,
140- css : {
141- preprocessorOptions : {
142- scss : {
143- api : 'modern' ,
170+ css : {
171+ preprocessorOptions : {
172+ scss : {
173+ api : 'modern' ,
174+ } ,
144175 } ,
145176 } ,
146- } ,
177+ } ;
147178} ) ;
0 commit comments