|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2020 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 { resolve } from 'path'; |
| 19 | +import sourcemaps from 'rollup-plugin-sourcemaps'; |
| 20 | +import rollupTypescriptPlugin from 'rollup-plugin-typescript2'; |
| 21 | +import typescript from 'typescript'; |
| 22 | +import json from 'rollup-plugin-json'; |
| 23 | +import pkg from '../package.json'; |
| 24 | +import compatPkg from './package.json'; |
| 25 | +import appPkg from './app/package.json'; |
| 26 | + |
| 27 | +const external = Object.keys(pkg.dependencies || {}); |
| 28 | + |
| 29 | +const plugins = [sourcemaps(), json()]; |
| 30 | + |
| 31 | +const typescriptPlugin = rollupTypescriptPlugin({ |
| 32 | + typescript, |
| 33 | + tsconfigOverride: { |
| 34 | + compilerOptions: { |
| 35 | + declaration: false |
| 36 | + } |
| 37 | + } |
| 38 | +}); |
| 39 | + |
| 40 | +/** |
| 41 | + * Individual Component Builds |
| 42 | + */ |
| 43 | +const appBuilds = [ |
| 44 | + /** |
| 45 | + * App Browser Builds |
| 46 | + */ |
| 47 | + { |
| 48 | + input: `${__dirname}/app/index.ts`, |
| 49 | + output: [ |
| 50 | + { |
| 51 | + file: resolve(__dirname, 'app', appPkg.main), |
| 52 | + format: 'cjs', |
| 53 | + sourcemap: true |
| 54 | + }, |
| 55 | + { |
| 56 | + file: resolve(__dirname, 'app', appPkg.module), |
| 57 | + format: 'es', |
| 58 | + sourcemap: true |
| 59 | + } |
| 60 | + ], |
| 61 | + plugins: [...plugins, typescriptPlugin], |
| 62 | + external |
| 63 | + } |
| 64 | +]; |
| 65 | + |
| 66 | +const componentBuilds = compatPkg.components |
| 67 | + // The "app" component is treated differently because it doesn't depend on itself. |
| 68 | + .filter(component => component !== 'app') |
| 69 | + .map(component => { |
| 70 | + const pkg = require(`${__dirname}/${component}/package.json`); |
| 71 | + return [ |
| 72 | + { |
| 73 | + input: `${__dirname}/${component}/index.ts`, |
| 74 | + output: [ |
| 75 | + { |
| 76 | + file: resolve(__dirname, component, pkg.main), |
| 77 | + format: 'cjs', |
| 78 | + sourcemap: true |
| 79 | + }, |
| 80 | + { |
| 81 | + file: resolve(__dirname, component, pkg.module), |
| 82 | + format: 'es', |
| 83 | + sourcemap: true |
| 84 | + } |
| 85 | + ], |
| 86 | + plugins: [...plugins, typescriptPlugin], |
| 87 | + external |
| 88 | + } |
| 89 | + ]; |
| 90 | + }) |
| 91 | + .reduce((a, b) => a.concat(b), []); |
| 92 | + |
| 93 | +export default [...appBuilds, ...componentBuilds]; |
0 commit comments