|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2021 Google LLC |
| 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 tmp from 'tmp'; |
| 19 | +import json from '@rollup/plugin-json'; |
| 20 | +import alias from '@rollup/plugin-alias'; |
| 21 | +import typescriptPlugin from 'rollup-plugin-typescript2'; |
| 22 | +import typescript from 'typescript'; |
| 23 | + |
| 24 | +import pkg from './package.json'; |
| 25 | + |
| 26 | +// This rollup configuration creates a single non-minified build for browser |
| 27 | +// testing. You can test code changes by running `yarn build:debug`. This |
| 28 | +// creates the file "dist/index.esm2017.js" that you can use in your sample |
| 29 | +// app as a replacement for |
| 30 | +// "node_modules/@firebase/firestore/dist/index.esm2017.js". |
| 31 | + |
| 32 | +const browserPlugins = function () { |
| 33 | + return [ |
| 34 | + typescriptPlugin({ |
| 35 | + typescript, |
| 36 | + tsconfigOverride: { |
| 37 | + compilerOptions: { |
| 38 | + target: 'es2017' |
| 39 | + } |
| 40 | + }, |
| 41 | + cacheDir: tmp.dirSync(), |
| 42 | + clean: true, |
| 43 | + abortOnError: false |
| 44 | + }), |
| 45 | + json({ preferConst: true }) |
| 46 | + ]; |
| 47 | +}; |
| 48 | + |
| 49 | +const aliasConfig = { |
| 50 | + entries: [ |
| 51 | + { |
| 52 | + find: /^(.*)\/platform\/([^.\/]*)(\.ts)?$/, |
| 53 | + replacement: `$1\/platform/browser/$2.ts` |
| 54 | + } |
| 55 | + ] |
| 56 | +}; |
| 57 | + |
| 58 | +const browserDeps = [ |
| 59 | + ...Object.keys(Object.assign({}, pkg.peerDependencies, pkg.dependencies)), |
| 60 | + '@firebase/app' |
| 61 | +]; |
| 62 | + |
| 63 | +export default [ |
| 64 | + { |
| 65 | + input: './src/index.ts', |
| 66 | + output: { |
| 67 | + file: pkg.browser, |
| 68 | + format: 'es', |
| 69 | + sourcemap: true |
| 70 | + }, |
| 71 | + plugins: [alias(aliasConfig), ...browserPlugins()], |
| 72 | + external: id => { |
| 73 | + return [...browserDeps, '@firebase/firestore'].some( |
| 74 | + dep => id === dep || id.startsWith(`${dep}/`) |
| 75 | + ); |
| 76 | + }, |
| 77 | + treeshake: { |
| 78 | + moduleSideEffects: false |
| 79 | + } |
| 80 | + } |
| 81 | +]; |
0 commit comments