@@ -21,7 +21,6 @@ import json from 'rollup-plugin-json';
21
21
import typescriptPlugin from 'rollup-plugin-typescript2' ;
22
22
import replace from 'rollup-plugin-replace' ;
23
23
import copy from 'rollup-plugin-copy-assets' ;
24
- import sourcemaps from 'rollup-plugin-sourcemaps' ;
25
24
import typescript from 'typescript' ;
26
25
import { terser } from 'rollup-plugin-terser' ;
27
26
@@ -30,8 +29,10 @@ import memoryPkg from './memory/package.json';
30
29
31
30
import {
32
31
appendPrivatePrefixTransformers ,
33
- manglePrivatePropertiesOptions
34
- } from './terser.config' ;
32
+ manglePrivatePropertiesOptions ,
33
+ resolveNodeExterns ,
34
+ resolveBrowserExterns
35
+ } from './rollup.shared' ;
35
36
36
37
// This Firestore Rollup configuration provides a number of different builds:
37
38
// - Browser builds that support persistence in ES5 CJS and ES5 ESM formats and
@@ -53,22 +54,6 @@ import {
53
54
54
55
// MARK: Browser builds
55
56
56
- const browserDeps = Object . keys (
57
- Object . assign ( { } , pkg . peerDependencies , pkg . dependencies )
58
- ) ;
59
-
60
- const nodeDeps = [ ...browserDeps , 'util' , 'path' ] ;
61
-
62
- /** Resolves the external dependencies for the browser build. */
63
- function resolveBrowserExterns ( id ) {
64
- return browserDeps . some ( dep => id === dep || id . startsWith ( `${ dep } /` ) ) ;
65
- }
66
-
67
- /** Resolves the external dependencies for the Node build. */
68
- function resolveNodeExterns ( id ) {
69
- return nodeDeps . some ( dep => id === dep || id . startsWith ( `${ dep } /` ) ) ;
70
- }
71
-
72
57
/**
73
58
* Resolves the external dependencies for the Memory-based Firestore
74
59
* implementation. Verifies that no persistence sources are used by Firestore's
@@ -99,95 +84,44 @@ export function resolveMemoryExterns(deps, externsId, referencedBy) {
99
84
return deps . some ( dep => externsId === dep || externsId . startsWith ( `${ dep } /` ) ) ;
100
85
}
101
86
102
- const es5BuildPlugins = [
103
- typescriptPlugin ( {
104
- typescript,
105
- transformers : appendPrivatePrefixTransformers ,
106
- cacheRoot : `./.cache/es5.mangled/`
107
- } ) ,
108
- json ( ) ,
109
- terser ( manglePrivatePropertiesOptions )
110
- ] ;
111
-
112
- const es2017BuildPlugins = [
87
+ const browserBuildPlugins = [
113
88
typescriptPlugin ( {
114
89
typescript,
115
90
tsconfigOverride : {
116
91
compilerOptions : {
117
92
target : 'es2017'
118
93
}
119
94
} ,
120
- cacheRoot : './.cache/es2017.mangled /' ,
95
+ cacheRoot : './.cache/browser /' ,
121
96
transformers : appendPrivatePrefixTransformers
122
97
} ) ,
123
98
json ( { preferConst : true } ) ,
124
99
terser ( manglePrivatePropertiesOptions )
125
100
] ;
126
101
127
102
const browserBuilds = [
128
- // ES5 ESM Build (with persistence)
129
- {
130
- input : 'index.ts' ,
131
- output : { file : pkg . module , format : 'es' , sourcemap : true } ,
132
- plugins : es5BuildPlugins ,
133
- external : resolveBrowserExterns
134
- } ,
135
- // ES5 ESM Build (memory-only)
136
- {
137
- input : 'index.memory.ts' ,
138
- output : {
139
- file : path . resolve ( './memory' , memoryPkg . module ) ,
140
- format : 'es' ,
141
- sourcemap : true
142
- } ,
143
- plugins : es5BuildPlugins ,
144
- external : ( id , referencedBy ) =>
145
- resolveMemoryExterns ( browserDeps , id , referencedBy )
146
- } ,
147
- // ES2017 ESM build (with persistence)
103
+ // Persistence build
148
104
{
149
105
input : 'index.ts' ,
150
106
output : {
151
107
file : pkg . esm2017 ,
152
108
format : 'es' ,
153
109
sourcemap : true
154
110
} ,
155
- plugins : es2017BuildPlugins ,
111
+ plugins : browserBuildPlugins ,
156
112
external : resolveBrowserExterns
157
113
} ,
158
- // ES2017 ESM build (memory -only)
114
+ // Memory -only build
159
115
{
160
116
input : 'index.memory.ts' ,
161
117
output : {
162
118
file : path . resolve ( './memory' , memoryPkg . esm2017 ) ,
163
119
format : 'es' ,
164
120
sourcemap : true
165
121
} ,
166
- plugins : es2017BuildPlugins ,
122
+ plugins : browserBuildPlugins ,
167
123
external : ( id , referencedBy ) =>
168
124
resolveMemoryExterns ( browserDeps , id , referencedBy )
169
- } ,
170
- // ES5 CJS Build (with persistence)
171
- //
172
- // This build is based on the mangling in the ESM build above, since
173
- // Terser's Property name mangling doesn't work well with CJS's syntax.
174
- {
175
- input : pkg . module ,
176
- output : { file : pkg . browser , format : 'cjs' , sourcemap : true } ,
177
- plugins : [ sourcemaps ( ) ]
178
- } ,
179
- // ES5 CJS Build (memory-only)
180
- //
181
- // This build is based on the mangling in the ESM build above, since
182
- // Terser's Property name mangling doesn't work well with CJS's syntax.
183
- {
184
- input : path . resolve ( './memory' , memoryPkg . module ) ,
185
- output : {
186
- file : path . resolve ( './memory' , memoryPkg . browser ) ,
187
- format : 'cjs' ,
188
- sourcemap : true
189
- } ,
190
- plugins : [ sourcemaps ( ) ]
191
125
}
192
126
] ;
193
127
@@ -196,6 +130,9 @@ const browserBuilds = [
196
130
const nodeBuildPlugins = [
197
131
typescriptPlugin ( {
198
132
typescript,
133
+ compilerOptions : {
134
+ target : 'es2017'
135
+ } ,
199
136
cacheRoot : `./.cache/node/`
200
137
} ) ,
201
138
json ( ) ,
@@ -209,19 +146,19 @@ const nodeBuildPlugins = [
209
146
] ;
210
147
211
148
const nodeBuilds = [
212
- // ES5 CJS build (with persistence)
149
+ // Persistence build
213
150
{
214
151
input : 'index.node.ts' ,
215
- output : [ { file : pkg . main , format : 'cjs' , sourcemap : true } ] ,
152
+ output : [ { file : pkg . mainES2017 , format : 'cjs' , sourcemap : true } ] ,
216
153
plugins : nodeBuildPlugins ,
217
154
external : resolveNodeExterns
218
155
} ,
219
- // ES5 CJS build (memory -only)
156
+ // Memory -only build
220
157
{
221
158
input : 'index.node.memory.ts' ,
222
159
output : [
223
160
{
224
- file : path . resolve ( './memory' , memoryPkg . main ) ,
161
+ file : path . resolve ( './memory' , memoryPkg . mainES2017 ) ,
225
162
format : 'cjs' ,
226
163
sourcemap : true
227
164
}
0 commit comments