• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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 */
15
16const fs = require('fs');
17
18const path = require('path');
19
20const rollup = require('rollup');
21
22const resolve = require('rollup-plugin-node-resolve');
23
24const commonjs = require('rollup-plugin-commonjs');
25
26const json = require('rollup-plugin-json');
27
28const babel = require('rollup-plugin-babel');
29
30const typescript = require('rollup-plugin-typescript2');
31
32const { uglify } = require('rollup-plugin-uglify');
33
34const {
35  eslint
36} = require('rollup-plugin-eslint');
37
38const frameworkBanner = `var global=this; var process={env:{}}; ` + `var setTimeout=global.setTimeout;\n`;
39
40const frameworkBannerForJSAPIMock = `var global=globalThis;`;
41
42const onwarn = warning => {
43  // Silence circular dependency warning
44  if (warning.code === 'CIRCULAR_DEPENDENCY') {
45    return;
46  }
47  console.warn(`(!) ${warning.message}`);
48};
49
50const tsPlugin = typescript({
51  tsconfig: path.resolve(__dirname, 'tsconfig.json'),
52  check: true
53});
54
55const esPlugin = eslint({
56  include: ['**/*.ts'],
57  exclude: ['node_modules/**', 'lib/**']
58});
59
60const configInput = {
61  input: path.resolve(__dirname, 'runtime/preparation/index.ts'),
62  onwarn,
63  plugins: [
64    esPlugin,
65    tsPlugin,
66    json(),
67    resolve(),
68    commonjs(),
69    babel({
70      exclude: 'node_moduels/**'
71    }),
72    uglify()
73  ]
74};
75
76const configOutput = {
77  file: path.resolve(__dirname, 'dist/strip.native.min.js'),
78  format: 'umd',
79  banner: frameworkBanner
80};
81
82rollup.rollup(configInput).then(bundle => {
83  bundle.write(configOutput).then(() => {
84    countSize(configOutput.file);
85  });
86});
87
88function countSize(filePath) {
89  const file = path.relative(__dirname, filePath);
90  fs.stat(filePath, function (error, stats) {
91    if (error) {
92      console.error('file size is wrong');
93    } else {
94      const size = (stats.size / 1024).toFixed(2) + 'KB';
95      console.log(`generate snapshot file: ${file}...\nthe snapshot file size: ${size}...`);
96    }
97  });
98}
99
100