1/*
2 * Copyright (c) 2020 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://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,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15const babel = require('rollup-plugin-babel');
16const commonjs = require('@rollup/plugin-commonjs');
17const { eslint } = require('rollup-plugin-eslint');
18const prettier = require('rollup-plugin-prettier');
19const { nodeResolve } = require('@rollup/plugin-node-resolve');
20const { sizeSnapshot } = require('rollup-plugin-size-snapshot');
21const strip = require('@rollup/plugin-strip');
22const { terser } = require('rollup-plugin-terser');
23
24const format = 'umd';
25const name = 'ViewModel';
26const input = 'src/index.js';
27const extensions = ['.js'];
28const exclude = 'node_modules/**';
29const beautifyPlugins = [prettier({ parser: 'babel' }), sizeSnapshot()];
30const minimizePlugins = [terser(), sizeSnapshot()];
31
32const banner = `/*
33* Copyright (c) 2020 Huawei Device Co., Ltd.
34* Licensed under the Apache License, Version 2.0 (the "License");
35* you may not use this file except in compliance with the License.
36* You may obtain a copy of the License at
37*
38*     http://www.apache.org/licenses/LICENSE-2.0
39*
40* Unless required by applicable law or agreed to in writing, software
41* distributed under the License is distributed on an "AS IS" BASIS,
42* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43* See the License for the specific language governing permissions and
44* limitations under the License.
45*/`;
46
47module.exports = [
48  {
49    input,
50    plugins: [
51      eslint({ fix: true }),
52      strip({ functions: ['startTracing', 'stopTracing'] }),
53      nodeResolve({ extensions }),
54      commonjs(),
55      babel({ exclude, extensions })
56    ],
57    output: [
58      {
59        name,
60        banner,
61        format,
62        file: 'build/framework.js',
63        plugins: beautifyPlugins
64      },
65      {
66        name,
67        banner,
68        format,
69        file: 'build/framework.min.js',
70        plugins: minimizePlugins
71      }
72    ]
73  },
74  {
75    input,
76    plugins: [
77      eslint({ fix: true }),
78      nodeResolve({ extensions }),
79      commonjs(),
80      babel({ exclude, extensions })
81    ],
82    output: [
83      {
84        name,
85        banner,
86        format,
87        file: 'build/framework-dev.js',
88        plugins: beautifyPlugins
89      },
90      {
91        name,
92        banner,
93        format,
94        file: 'build/framework-dev.min.js',
95        plugins: minimizePlugins
96      }
97    ]
98  }
99];
100