@@ -6,11 +6,12 @@ import cleaner from 'rollup-plugin-cleaner';
66
77const extensions = [ '.js' , '.ts' , '.json' , '.tsx' , '.jsx' ] ;
88
9- function css ( ) {
9+ function css ( server = false ) {
1010 return {
1111 name : 'devtools-css' ,
1212 transform ( code , id ) {
1313 if ( ! id . endsWith ( '.css' ) ) return null ;
14+ if ( server ) return { code : '' , map : null } ;
1415 return {
1516 code : `const style = document.createElement('style');\nstyle.textContent = ${ JSON . stringify ( code ) } ;\ndocument.head.append(style);` ,
1617 map : null ,
@@ -49,40 +50,59 @@ function packageVersion() {
4950 } ;
5051}
5152
52- export default {
53- input : 'src/index.tsx' ,
54- output : {
55- format : 'esm' ,
56- dir : 'dist' ,
53+ function external ( id ) {
54+ return (
55+ id === 'solid-js' ||
56+ id . startsWith ( 'solid-js/' ) ||
57+ id === '@solidjs/web' ||
58+ id . startsWith ( '@solidjs/web/' )
59+ ) ;
60+ }
61+
62+ function config ( { input, entryFileNames, chunkFileNames, generate, server = false } ) {
63+ return {
64+ input,
65+ output : {
66+ format : 'esm' ,
67+ dir : 'dist' ,
68+ entryFileNames,
69+ chunkFileNames,
70+ assetFileNames : 'assets/[name]-[hash][extname]' ,
71+ sourcemap : true ,
72+ } ,
73+ external,
74+ plugins : [
75+ ...( server ? [ ] : [ cleaner ( { targets : [ './dist/' ] } ) ] ) ,
76+ css ( server ) ,
77+ assetUrl ( ) ,
78+ packageVersion ( ) ,
79+ babel ( {
80+ extensions,
81+ babelHelpers : 'bundled' ,
82+ presets : [
83+ [ '@babel/preset-env' , { targets : { esmodules : true } } ] ,
84+ '@babel/preset-typescript' ,
85+ [ 'babel-preset-solid' , { moduleName : '@solidjs/web' , generate } ] ,
86+ ] ,
87+ } ) ,
88+ nodeResolve ( { extensions, browser : ! server } ) ,
89+ cjs ( { extensions } ) ,
90+ ] ,
91+ } ;
92+ }
93+
94+ export default [
95+ config ( {
96+ input : 'src/index.tsx' ,
5797 entryFileNames : 'index.js' ,
5898 chunkFileNames : 'chunks/[name]-[hash].js' ,
59- assetFileNames : 'assets/[name]-[hash][extname]' ,
60- sourcemap : true ,
61- } ,
62- external ( id ) {
63- return (
64- id === 'solid-js' ||
65- id . startsWith ( 'solid-js/' ) ||
66- id === '@solidjs/web' ||
67- id . startsWith ( '@solidjs/web/' )
68- ) ;
69- } ,
70- plugins : [
71- cleaner ( { targets : [ './dist/' ] } ) ,
72- css ( ) ,
73- assetUrl ( ) ,
74- packageVersion ( ) ,
75- babel ( {
76- extensions,
77- babelHelpers : 'bundled' ,
78- presets : [
79- [ '@babel/preset-env' , { targets : { esmodules : true } } ] ,
80- '@babel/preset-typescript' ,
81- [ 'babel-preset-solid' , { moduleName : '@solidjs/web' , generate : 'dom' } ] ,
82- ] ,
83- } ) ,
84- nodeResolve ( { extensions, browser : true } ) ,
85- cjs ( { extensions } ) ,
86- ] ,
87- } ;
88-
99+ generate : 'dom' ,
100+ } ) ,
101+ config ( {
102+ input : 'src/server.tsx' ,
103+ entryFileNames : 'server.js' ,
104+ chunkFileNames : 'server-chunks/[name]-[hash].js' ,
105+ generate : 'ssr' ,
106+ server : true ,
107+ } ) ,
108+ ] ;
0 commit comments