xref: /aosp_15_r20/external/pigweed/rollup.config.js (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1// Copyright 2022 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
15import commonjs from '@rollup/plugin-commonjs';
16import resolve from '@rollup/plugin-node-resolve';
17import pluginTypescript from '@rollup/plugin-typescript';
18import path from 'path';
19import nodePolyfills from 'rollup-plugin-node-polyfills';
20import postcss from 'rollup-plugin-postcss';
21import sourceMaps from 'rollup-plugin-sourcemaps';
22import terser from '@rollup/plugin-terser';
23
24export default [
25  // Bundle proto collection into one UMD file for consumption from browser
26  {
27    input: path.join('dist', 'protos', 'collection.ts'),
28    output: [
29      {
30        file: path.join('dist', 'protos', 'collection.umd.js'),
31        format: 'umd',
32        sourcemap: true,
33        name: 'PigweedProtoCollection',
34      },
35    ],
36    plugins: [
37      pluginTypescript({ tsconfig: './tsconfig.json' }),
38      commonjs(),
39      resolve(),
40
41      // Resolve source maps to the original source
42      sourceMaps(),
43    ],
44  },
45  // Bundle Pigweed log component and modules
46  {
47    input: path.join('ts', 'logging.ts'),
48    output: [
49      {
50        file: path.join('dist', 'logging.umd.js'),
51        format: 'umd',
52        sourcemap: true,
53        name: 'PigweedLogging',
54        inlineDynamicImports: true,
55      },
56      {
57        file: path.join('dist', 'logging.mjs'),
58        format: 'esm',
59        sourcemap: true,
60        inlineDynamicImports: true,
61      },
62    ],
63    plugins: [
64      postcss({ plugins: [] }),
65      pluginTypescript({
66        tsconfig: './tsconfig.json',
67        exclude: ['**/*_test.ts'],
68      }),
69      nodePolyfills(),
70      resolve(),
71      commonjs(),
72
73      // Resolve source maps to the original source
74      sourceMaps(),
75    ],
76  },
77  // Bundle pw_console's web counterparts
78  {
79    input: path.join('ts', 'console.ts'),
80    output: [
81      {
82        file: path.join('dist', 'pw_console.umd.js'),
83        format: 'umd',
84        sourcemap: true,
85        name: 'PWConsole',
86        inlineDynamicImports: true,
87      },
88      {
89        file: path.join('dist', 'pw_console.mjs'),
90        format: 'esm',
91        sourcemap: true,
92        inlineDynamicImports: true,
93      },
94    ],
95    plugins: [
96      postcss({ plugins: [] }),
97      pluginTypescript({
98        tsconfig: './tsconfig.json',
99        exclude: ['**/*_test.ts'],
100      }),
101      nodePolyfills(),
102      resolve(),
103      commonjs(),
104
105      // Resolve source maps to the original source
106      sourceMaps(),
107
108      // Minify builds
109      terser(),
110    ],
111  },
112  // Bundle Pigweed modules
113  {
114    input: path.join('ts', 'index.ts'),
115    output: [
116      {
117        file: path.join('dist', 'index.umd.js'),
118        format: 'umd',
119        sourcemap: true,
120        name: 'Pigweed',
121      },
122      {
123        file: path.join('dist', 'index.mjs'),
124        format: 'esm',
125        sourcemap: true,
126      },
127    ],
128    plugins: [
129      pluginTypescript({
130        tsconfig: './tsconfig.json',
131        exclude: ['**/*_test.ts'],
132      }),
133      nodePolyfills(),
134      resolve(),
135      commonjs(),
136
137      // Resolve source maps to the original source
138      sourceMaps(),
139    ],
140  },
141];
142