|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2018 Google Inc. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +import * as path from 'path'; |
| 19 | + |
| 20 | +import json from 'rollup-plugin-json'; |
| 21 | +import typescriptPlugin from 'rollup-plugin-typescript2'; |
| 22 | +import replace from 'rollup-plugin-replace'; |
| 23 | +import copy from 'rollup-plugin-copy-assets'; |
| 24 | +import typescript from 'typescript'; |
| 25 | +import { terser } from 'rollup-plugin-terser'; |
| 26 | + |
| 27 | +import pkg from './package.json'; |
| 28 | +import memoryPkg from './memory/package.json'; |
| 29 | + |
| 30 | +import { |
| 31 | + appendPrivatePrefixTransformers, |
| 32 | + manglePrivatePropertiesOptions, |
| 33 | + resolveNodeExterns, |
| 34 | + resolveBrowserExterns |
| 35 | +} from './rollup.shared'; |
| 36 | + |
| 37 | +// Firestore is released in a number of different build configurations: |
| 38 | +// - Browser builds that support persistence in ES5 CJS and ES5 ESM formats and |
| 39 | +// ES2017 in ESM format. |
| 40 | +// - In-memory Browser builds that support persistence in ES5 CJS and ES5 ESM |
| 41 | +// formats and ES2017 in ESM format. |
| 42 | +// - A NodeJS build that supports persistence (to be used with an IndexedDb |
| 43 | +// shim) |
| 44 | +// - A in-memory only NodeJS build |
| 45 | +// |
| 46 | +// The in-memory builds are roughly 130 KB smaller, but throw an exception |
| 47 | +// for calls to `enablePersistence()` or `clearPersistence()`. |
| 48 | +// |
| 49 | +// We use two different rollup pipelines to take advantage of tree shaking, |
| 50 | +// as Rollup does not support tree shaking for Typescript classes transpiled |
| 51 | +// down to ES5 (see https://bit.ly/340P23U). The build pipeline in this file |
| 52 | +// produces tree-shaken ES2017 builds that are consumed by the ES5 builds in |
| 53 | +// `rollup.config.es.js`. |
| 54 | +// |
| 55 | +// All browser builds rely on Terser's property name mangling to reduce code |
| 56 | +// size. |
| 57 | +// |
| 58 | +// See https://g3doc/firebase/jscore/g3doc/contributing/builds.md |
| 59 | +// for a description of the various JavaScript formats used in our SDKs. |
| 60 | + |
| 61 | +// MARK: Browser builds |
| 62 | + |
| 63 | +const browserBuildPlugins = [ |
| 64 | + typescriptPlugin({ |
| 65 | + typescript, |
| 66 | + tsconfigOverride: { |
| 67 | + compilerOptions: { |
| 68 | + target: 'es2017' |
| 69 | + } |
| 70 | + }, |
| 71 | + clean: true, |
| 72 | + transformers: appendPrivatePrefixTransformers |
| 73 | + }), |
| 74 | + json({ preferConst: true }), |
| 75 | + terser(manglePrivatePropertiesOptions) |
| 76 | +]; |
| 77 | + |
| 78 | +const browserBuilds = [ |
| 79 | + // Persistence build |
| 80 | + { |
| 81 | + input: 'index.ts', |
| 82 | + output: { |
| 83 | + file: pkg.esm2017, |
| 84 | + format: 'es', |
| 85 | + sourcemap: true |
| 86 | + }, |
| 87 | + plugins: browserBuildPlugins, |
| 88 | + external: resolveBrowserExterns |
| 89 | + }, |
| 90 | + // Memory-only build |
| 91 | + { |
| 92 | + input: 'index.memory.ts', |
| 93 | + output: { |
| 94 | + file: path.resolve('./memory', memoryPkg.esm2017), |
| 95 | + format: 'es', |
| 96 | + sourcemap: true |
| 97 | + }, |
| 98 | + plugins: browserBuildPlugins, |
| 99 | + external: resolveBrowserExterns |
| 100 | + } |
| 101 | +]; |
| 102 | + |
| 103 | +// MARK: Node builds |
| 104 | + |
| 105 | +const nodeBuildPlugins = [ |
| 106 | + typescriptPlugin({ |
| 107 | + typescript, |
| 108 | + tsconfigOverride: { |
| 109 | + compilerOptions: { |
| 110 | + target: 'es2017' |
| 111 | + } |
| 112 | + }, |
| 113 | + clean: true |
| 114 | + }), |
| 115 | + json(), |
| 116 | + // Needed as we also use the *.proto files |
| 117 | + copy({ |
| 118 | + assets: ['./src/protos'] |
| 119 | + }), |
| 120 | + replace({ |
| 121 | + 'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('src/protos') |
| 122 | + }) |
| 123 | +]; |
| 124 | + |
| 125 | +const nodeBuilds = [ |
| 126 | + // Persistence build |
| 127 | + { |
| 128 | + input: 'index.node.ts', |
| 129 | + output: [{ file: pkg['main-esm2017'], format: 'es', sourcemap: true }], |
| 130 | + plugins: nodeBuildPlugins, |
| 131 | + external: resolveNodeExterns |
| 132 | + }, |
| 133 | + // Memory-only build |
| 134 | + { |
| 135 | + input: 'index.node.memory.ts', |
| 136 | + output: [ |
| 137 | + { |
| 138 | + file: path.resolve('./memory', memoryPkg['main-esm2017']), |
| 139 | + format: 'es', |
| 140 | + sourcemap: true |
| 141 | + } |
| 142 | + ], |
| 143 | + plugins: nodeBuildPlugins, |
| 144 | + external: resolveNodeExterns |
| 145 | + } |
| 146 | +]; |
| 147 | + |
| 148 | +export default [...browserBuilds, ...nodeBuilds]; |
0 commit comments