|
| 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 json from 'rollup-plugin-json'; |
| 21 | +import pkg from './package.json'; |
| 22 | +import { importPathTransformer } from '../../scripts/exp/ts-transform-import-path'; |
| 23 | + |
| 24 | +const deps = Object.keys( |
| 25 | + Object.assign({}, pkg.peerDependencies, pkg.dependencies) |
| 26 | +); |
| 27 | + |
| 28 | +/** |
| 29 | + * ES5 Builds |
| 30 | + */ |
| 31 | +const es5BuildPlugins = [ |
| 32 | + typescriptPlugin({ |
| 33 | + typescript, |
| 34 | + clean: true, |
| 35 | + abortOnError: false, |
| 36 | + transformers: [importPathTransformer] |
| 37 | + }), |
| 38 | + json() |
| 39 | +]; |
| 40 | + |
| 41 | +const es5Builds = [ |
| 42 | + /** |
| 43 | + * Browser Builds |
| 44 | + */ |
| 45 | + { |
| 46 | + input: 'src/index.ts', |
| 47 | + output: [{ file: pkg.browser, format: 'es', sourcemap: true }], |
| 48 | + plugins: es5BuildPlugins, |
| 49 | + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), |
| 50 | + treeshake: { |
| 51 | + moduleSideEffects: false |
| 52 | + } |
| 53 | + }, |
| 54 | + /** |
| 55 | + * Node.js Build |
| 56 | + */ |
| 57 | + { |
| 58 | + input: 'src/index.ts', |
| 59 | + output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], |
| 60 | + plugins: es5BuildPlugins, |
| 61 | + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), |
| 62 | + treeshake: { |
| 63 | + moduleSideEffects: false |
| 64 | + } |
| 65 | + } |
| 66 | +]; |
| 67 | + |
| 68 | +/** |
| 69 | + * ES2017 Builds |
| 70 | + */ |
| 71 | +const es2017BuildPlugins = [ |
| 72 | + typescriptPlugin({ |
| 73 | + typescript, |
| 74 | + tsconfigOverride: { |
| 75 | + compilerOptions: { |
| 76 | + target: 'es2017' |
| 77 | + } |
| 78 | + }, |
| 79 | + abortOnError: false, |
| 80 | + clean: true, |
| 81 | + transformers: [importPathTransformer] |
| 82 | + }), |
| 83 | + json({ |
| 84 | + preferConst: true |
| 85 | + }) |
| 86 | +]; |
| 87 | + |
| 88 | +const es2017Builds = [ |
| 89 | + /** |
| 90 | + * Browser Builds |
| 91 | + */ |
| 92 | + { |
| 93 | + input: 'src/index.ts', |
| 94 | + output: { |
| 95 | + file: pkg.esm2017, |
| 96 | + format: 'es', |
| 97 | + sourcemap: true |
| 98 | + }, |
| 99 | + plugins: es2017BuildPlugins, |
| 100 | + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), |
| 101 | + treeshake: { |
| 102 | + moduleSideEffects: false |
| 103 | + } |
| 104 | + } |
| 105 | +]; |
| 106 | + |
| 107 | +export default [...es5Builds, ...es2017Builds]; |
0 commit comments