1+ import alias from '@rollup/plugin-alias' ;
12import commonjs from '@rollup/plugin-commonjs' ;
23import inject from '@rollup/plugin-inject' ;
34import json from '@rollup/plugin-json' ;
45import nodeResolve from '@rollup/plugin-node-resolve' ;
6+ import replace from '@rollup/plugin-replace' ;
57import terser from '@rollup/plugin-terser' ;
8+ import path from 'path' ;
9+ import { fileURLToPath } from 'url' ;
10+
11+ const __filename = fileURLToPath ( import . meta. url ) ;
12+ const __dirname = path . dirname ( __filename ) ;
613
714/**
815 * @returns {import('rollup').RollupOptions }
@@ -13,29 +20,63 @@ export default (commandLineArgs) => {
1320 // Clears rollup CLI warning https://github.com/rollup/rollup/issues/2694
1421 delete commandLineArgs . sourceMap ;
1522
16- return {
17- input : 'lib/index.js' ,
18- output : {
19- file : 'dist/bundle.mjs' ,
20- format : 'esm' ,
21- sourcemap : sourceMap
23+ return [
24+ {
25+ input : 'lib/index.js' ,
26+ output : {
27+ file : 'dist/bundle.mjs' ,
28+ format : 'esm' ,
29+ sourcemap : sourceMap
30+ } ,
31+ plugins : [
32+ json ( ) ,
33+ nodeResolve ( { preferBuiltins : false , browser : true } ) ,
34+ commonjs ( { } ) ,
35+ inject ( {
36+ Buffer : [ 'buffer' , 'Buffer' ] ,
37+ ReadableStream : [ 'web-streams-polyfill/ponyfill' , 'ReadableStream' ] ,
38+ // Used by can-ndjson-stream
39+ TextDecoder : [ 'text-encoding' , 'TextDecoder' ]
40+ } ) ,
41+ terser ( { sourceMap } )
42+ ] ,
43+ // This makes life easier
44+ external : [
45+ // This has dynamic logic - makes bundling hard
46+ 'cross-fetch'
47+ ]
2248 } ,
23- plugins : [
24- json ( ) ,
25- nodeResolve ( { preferBuiltins : false , browser : true } ) ,
26- commonjs ( { } ) ,
27- inject ( {
28- Buffer : [ 'buffer' , 'Buffer' ] ,
29- ReadableStream : [ 'web-streams-polyfill/ponyfill' , 'ReadableStream' ] ,
30- // Used by can-ndjson-stream
31- TextDecoder : [ 'text-encoding' , 'TextDecoder' ]
32- } ) ,
33- terser ( { sourceMap } )
34- ] ,
35- // This makes life easier
36- external : [
37- // This has dynamic logic - makes bundling hard
38- 'cross-fetch'
39- ]
40- } ;
49+ {
50+ input : 'lib/dev/index.js' ,
51+ output : [
52+ {
53+ file : 'dist/dev/bundle.dev.mjs' ,
54+ format : 'esm' ,
55+ sourcemap : sourceMap
56+ } ,
57+ {
58+ file : 'dist/dev/bundle.dev.cjs' ,
59+ format : 'cjs' ,
60+ sourcemap : sourceMap
61+ }
62+ ] ,
63+ plugins : [
64+ replace ( {
65+ delimiters : [ '' , '' ] ,
66+ preventAssignment : true
67+ } ) ,
68+ nodeResolve ( { preferBuiltins : false , browser : true } ) ,
69+ commonjs ( { } ) ,
70+ alias ( {
71+ entries : [
72+ { find : 'fs' , replacement : path . resolve ( __dirname , 'vendored/empty.js' ) } ,
73+ { find : 'path' , replacement : path . resolve ( __dirname , 'vendored/empty.js' ) } ,
74+ { find : 'crypto' , replacement : path . resolve ( __dirname , 'vendored/empty.js' ) }
75+ // add others as needed
76+ ]
77+ } )
78+ ] ,
79+ external : [ '@powersync/common' ]
80+ }
81+ ] ;
4182} ;
0 commit comments