1- import typescript from '@rollup/plugin-typescript' ;
21import { vanillaExtractPlugin } from '@vanilla-extract/rollup-plugin' ;
3- import fs from 'fs' ;
4- import path from 'path' ;
52import type { ModuleFormat , OutputOptions , RollupOptions } from 'rollup' ;
6- import { defineConfig , rollup } from 'rollup' ;
3+ import { defineConfig } from 'rollup' ;
74import { dependencies , peerDependencies } from './package.json' ;
8- import { preserveJsxImports } from './tools/preserve-jsx-imports' ;
95import withSolid from './tools/with-solid' ;
106
117const externals = [
@@ -18,8 +14,6 @@ const externals = [
1814 'solid-use/props' ,
1915] ;
2016
21- const cssFileFilter = / \. c s s \. ( j s | m j s | j s x | t s | t s x ) ( \? u s e d ) ? $ / ;
22-
2317const solidConfig = withSolid ( {
2418 input : {
2519 index : 'src/index.tsx' ,
@@ -28,115 +22,9 @@ const solidConfig = withSolid({
2822 } ,
2923 targets : [ 'esm' , 'cjs' ] ,
3024 external : externals ,
31- output : [ buildOutput ( 'esm' ) , buildOutput ( 'cjs' ) ] ,
25+ output : [ buildOutput ( 'esm' ) ] ,
3226 plugins : [
3327 vanillaExtractPlugin ( ) ,
34- {
35- name : 'generate-vanilla-extract-source' ,
36- async closeBundle ( ) {
37- const build = await rollup ( {
38- input : {
39- index : 'dist/source/index.jsx' ,
40- 'lightTheme.css' : 'dist/source/lib/themes/light-theme.css.js' ,
41- 'darkTheme.css' : 'dist/source/lib/themes/dark-theme.css.js' ,
42- } ,
43- treeshake : false ,
44- external : externals ,
45- plugins : [
46- typescript ( { tsconfig : './tsconfig.source.json' } ) ,
47- // Source folder should not be edited, but we need to manually
48- // preserve custom jsx imports like styled.div
49- preserveJsxImports ( ) ,
50- {
51- name : 'transfer-vanilla-extract-source' ,
52- async renderChunk ( code , info ) {
53- const id = info . facadeModuleId ?? '' ;
54- // We need to keep untouched files that are not handled by Vanilla Extract
55- if ( ! cssFileFilter . test ( id ) ) {
56- return ;
57- }
58- // The path should be resolved removing the query parameter that
59- // rollup applies like ?used / ?unused
60- const index = id . indexOf ( '?' ) ;
61- const filePath = index === - 1 ? id : id . substring ( 0 , index ) ;
62- const resolvedPath = filePath . split ( path . sep ) . join ( '/' ) ;
63-
64- // This is the base path that contain the generated css from vanilla-extract.
65- const builtPath = resolvedPath . replace (
66- '/dist/source/' ,
67- '/dist/esm/' ,
68- ) ;
69-
70- // @vanilla -extract/rollup-plugin generate a css file with the suffix `.ts.vanilla.css`.
71- // It will be in the same folder of the js file due to preserveModules.
72- const cssFile = builtPath . replace ( / \. j s $ / , '.ts.vanilla.css' ) ;
73-
74- let jsFile : string ;
75- // Entry inputs should be handled in a different way
76- // since the facadeModuleId is different from the file name that
77- // will be used for outputting the .js file.
78- if ( info . isEntry ) {
79- const parsedFileName = path . parse ( info . fileName ) ;
80- const parsedFacadeModuleId = path . parse ( id ) ;
81- parsedFacadeModuleId . name = parsedFileName . name ;
82- parsedFacadeModuleId . base = `${ parsedFileName . name } ${ parsedFileName . ext } ` ;
83- jsFile = path
84- . format ( parsedFacadeModuleId )
85- . split ( path . sep )
86- . join ( '/' )
87- . replace ( '/dist/source/' , '/dist/esm/' ) ;
88- } else {
89- jsFile = builtPath . replace ( / \. j s $ / , '.vanilla.js' ) ;
90- }
91- try {
92- const jsCode = fs . readFileSync ( jsFile , {
93- encoding : 'utf8' ,
94- } ) ;
95-
96- // Sometimes Vanilla extract doesn't generate the css file,
97- // for example when the .js file contains only css variables or
98- // something that should not be added to the stylesheet.
99- if ( fs . existsSync ( cssFile ) ) {
100- const cssCode = fs . readFileSync ( cssFile , {
101- encoding : 'utf8' ,
102- } ) ;
103- const cssParsedPath = path . parse ( cssFile ) ;
104- const chunkPath = path . parse ( info . fileName ) ;
105- // We need to emit every css file present in the dist/esm folder
106- // that has been generated with Vanilla Extract
107- this . emitFile ( {
108- type : 'asset' ,
109- source : cssCode ,
110- fileName : `${ chunkPath . dir } /${ cssParsedPath . name } ${ cssParsedPath . ext } ` ,
111- } ) ;
112- }
113- return {
114- code : jsCode ,
115- map : info . map ,
116- } ;
117- } catch ( e ) {
118- console . log ( e ) ;
119- }
120- } ,
121- } ,
122- ] ,
123- } ) ;
124- await build . write ( {
125- dir : './dist/source-gen' ,
126- preserveModules : true ,
127- preserveModulesRoot : 'dist/source' ,
128- exports : 'named' ,
129- entryFileNames ( { name} ) {
130- return `${ name . replace ( / \. c s s $ / , '.css.vanilla' ) } .[ext]` ;
131- } ,
132- assetFileNames ( { name} ) {
133- return name ?. replace ( / ^ d i s t \/ s o u r c e \/ / , '' ) ?? '' ;
134- } ,
135- } ) ;
136- } ,
137- } ,
138- // This is needed in order to fix some side effects that are not resolved manually.
139- // TODO: need to check this
14028 {
14129 name : 'no-treeshake' ,
14230 transform ( ) {
0 commit comments