|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2019 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 typescriptPlugin from 'rollup-plugin-typescript2'; |
| 19 | +import typescript from 'typescript'; |
| 20 | +import pkg from './package.json'; |
| 21 | + |
| 22 | +const deps = Object.keys( |
| 23 | + Object.assign({}, pkg.peerDependencies, pkg.dependencies) |
| 24 | +); |
| 25 | + |
| 26 | +/** |
| 27 | + * ES5 Builds |
| 28 | + */ |
| 29 | +const es5BuildPlugins = [ |
| 30 | + typescriptPlugin({ |
| 31 | + typescript |
| 32 | + }) |
| 33 | +]; |
| 34 | + |
| 35 | +const es5Builds = [ |
| 36 | + /** |
| 37 | + * Browser Builds |
| 38 | + */ |
| 39 | + { |
| 40 | + input: 'index.ts', |
| 41 | + output: [ |
| 42 | + { file: pkg.browser, format: 'cjs', sourcemap: true }, |
| 43 | + { file: pkg.module, format: 'es', sourcemap: true } |
| 44 | + ], |
| 45 | + plugins: es5BuildPlugins, |
| 46 | + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) |
| 47 | + }, |
| 48 | + /** |
| 49 | + * Node.js Build |
| 50 | + */ |
| 51 | + { |
| 52 | + input: 'index.node.ts', |
| 53 | + output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], |
| 54 | + plugins: es5BuildPlugins, |
| 55 | + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) |
| 56 | + } |
| 57 | +]; |
| 58 | + |
| 59 | +/** |
| 60 | + * ES2017 Builds |
| 61 | + */ |
| 62 | +const es2017BuildPlugins = [ |
| 63 | + typescriptPlugin({ |
| 64 | + typescript, |
| 65 | + tsconfigOverride: { |
| 66 | + compilerOptions: { |
| 67 | + target: 'es2017' |
| 68 | + } |
| 69 | + } |
| 70 | + }) |
| 71 | +]; |
| 72 | + |
| 73 | +const es2017Builds = [ |
| 74 | + /** |
| 75 | + * Browser Builds |
| 76 | + */ |
| 77 | + { |
| 78 | + input: 'index.ts', |
| 79 | + output: { |
| 80 | + file: pkg.esm2017, |
| 81 | + format: 'es', |
| 82 | + sourcemap: true |
| 83 | + }, |
| 84 | + plugins: es2017BuildPlugins, |
| 85 | + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) |
| 86 | + } |
| 87 | +]; |
| 88 | + |
| 89 | +export default [...es5Builds, ...es2017Builds]; |
0 commit comments