@@ -9,64 +9,62 @@ const path = require('node:path')
99const production = ! process . env . ROLLUP_WATCH ;
1010
1111
12- /* get svelte input paths (split by :) from cmd line arg */
12+ /* export an array of rollup configs - one for each input svelte file - using
13+ additional command line args supplied from lua */
14+ export default cmd => {
1315
14- const svelteInputPaths = process . argv
15- . filter ( d => d . startsWith ( "--svelte-in-paths=" ) )
16- . map ( d => d . replace ( "--svelte-in-paths=" , "" ) )
17- . join ( ":" )
18- . split ( ":" )
19- . filter ( d => d != "" )
16+ const svelteInputPaths =
17+ cmd [ "svelte-in-paths" ] . split ( ":" ) . filter ( d => d != "" )
2018
21- // if no svelte paths, bail out early
22- if ( svelteInputPaths == undefined || svelteInputPaths . length == 0 ) {
23- console . log ( "No Svelte filtes found; skipping Svelte compilation" )
24- Deno . exit ( 0 )
25- }
26-
27- /* get quarto render dir from cmd line arg */
19+ // if no svelte paths, bail out early
20+ if ( svelteInputPaths == undefined || svelteInputPaths . length == 0 ) {
21+ console . log ( "No Svelte filtes found; skipping Svelte compilation" )
22+ process . exit ( 0 )
23+ }
2824
29- let quartoRenderPath = process . argv
30- . filter ( d => d . startsWith ( "--quarto-out-path=" ) )
31- . map ( d => d . replace ( "--quarto-out-path=" , "" ) )
25+ /* get quarto render dir from cmd line arg */
26+ const quartoRenderPath = cmd [ "quarto-out-path" ]
27+ if ( quartoRenderPath == undefined ) {
28+ console . error (
29+ "Error: supply a --quarto-out-path. Please report this to " +
30+ "the Sverto developer." )
31+ process . exit ( 1 )
32+ }
3233
33- if ( quartoRenderPath == undefined || quartoRenderPath . length != 1 ) {
34- console . error ( "There should be 1 --quarto-out-path argument." )
35- }
36- quartoRenderPath = quartoRenderPath [ 0 ]
34+ return svelteInputPaths . map (
3735
38- /* export an array of rollup configs: one for each input svelte file */
39- export default svelteInputPaths . map (
36+ svelteFile => ( {
37+ input : svelteFile ,
38+ output : {
39+ format : "es" ,
40+ dir : path . join (
41+ quartoRenderPath ,
42+ path . dirname ( svelteFile ) ) ,
43+ sourcemap : true
44+ } ,
45+ plugins : [
46+ svelte ( {
47+ // css is added to the js bundle instead
48+ emitCss : false ,
49+ compilerOptions : {
50+ // required for ojs reactivity
51+ accessors : true ,
52+ dev : ! production ,
53+ }
54+ } ) ,
55+ resolve ( {
56+ browser : true ,
57+ dedupe : [ "svelte" ]
58+ } ) ,
59+ commonjs ( ) ,
60+ production && terser ( )
61+ ]
62+ } )
63+
64+ )
4065
41- svelteFile => ( {
42- input : svelteFile ,
43- output : {
44- format : "es" ,
45- dir : path . join (
46- quartoRenderPath ,
47- path . dirname ( svelteFile ) ) ,
48- sourcemap : true
49- } ,
50- plugins : [
51- svelte ( {
52- // css is added to the js bundle instead
53- emitCss : false ,
54- compilerOptions : {
55- // required for ojs reactivity
56- accessors : true ,
57- dev : ! production ,
58- }
59- } ) ,
60- resolve ( {
61- browser : true ,
62- dedupe : [ "svelte" ]
63- } ) ,
64- commonjs ( ) ,
65- production && terser ( )
66- ]
67- } )
66+ }
6867
69- )
7068
7169
7270
0 commit comments