idlize

Форк
0
/
rollup.config.main.mjs 
107 строк · 3.5 Кб
1
/*
2
 * Copyright (c) 2024 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

16
import nodeResolve from "@rollup/plugin-node-resolve";
17
import os from 'os';
18
import replace from '@rollup/plugin-replace';
19
import terser from "@rollup/plugin-terser";
20
import typescript from "@rollup/plugin-typescript";
21
import * as path from "path";
22

23
const platform = os.platform()
24
const isWindows = (platform === 'win32')
25

26
function crossPathRelative(from, to) {
27
    if (isWindows) {
28
        return path.relative(from, to).replace(/\\/g, '\\\\')
29
    } else {
30
        return path.relative(from, to)
31
    }
32
}
33

34
const mode = process.env.mode
35
const arch = process.env.arch
36

37
console.log(`rollup args: mode = ${mode}, arch = ${arch}`)
38
const generatedDir = `generated`
39
const arkoalaArkuiSrcDir = `${generatedDir}/${mode}/koalaui/arkoala-arkui/src`
40
const tsconfigFile = path.resolve(`tsconfig-${mode == 'subset' ? mode : 'generated'}.json`)
41
const outDir = path.resolve('lib')
42

43
const ENABLE_SOURCE_MAPS = true;  // Enable for debugging
44

45
/** @type {import("rollup").RollupOptions} */
46
export default {
47
    input: `${arkoalaArkuiSrcDir}/main.ts`,
48
    output: {
49
        file: "./lib/main.js",
50
        format: "commonjs",
51
        sourcemap: ENABLE_SOURCE_MAPS,
52
        sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {
53
            // For some reason Rollup adds extra ../ to relativeSourcePath, remove it
54
            let absolute = path.join(sourcemapPath, relativeSourcePath);
55
            let relative = path.relative(path.dirname(sourcemapPath), absolute);
56
            return relative
57
        },
58
        plugins: [
59
            // terser()
60
        ],
61
        banner: [
62
            "#!/usr/bin/env node",
63
            APACHE_LICENSE_HEADER()
64
        ].join("\n"),
65
    },
66
    external: [],
67
    plugins: [
68
        typescript({
69
            outputToFilesystem: false,
70
            module: "ESNext",
71
            sourceMap: ENABLE_SOURCE_MAPS,
72
            declarationMap: false,
73
            declaration: false,
74
            composite: false,
75
            tsconfig: tsconfigFile,
76
            filterRoot: '.'
77
        }),
78
        nodeResolve({
79
            extensions: [".js", ".mjs", ".cjs", ".ts", ".cts", ".mts"]
80
        }),
81
        replace({
82
            'LOAD_NATIVE': `require('${crossPathRelative(outDir, 'native/NativeBridgeNapi.node')}')`,
83
            preventAssignment: true
84
        })
85
    ]
86
}
87

88
function APACHE_LICENSE_HEADER() {
89
    return `
90
/**
91
* @license
92
* Copyright (c) ${new Date().getUTCFullYear()} Huawei Device Co., Ltd.
93
* Licensed under the Apache License, Version 2.0 (the "License");
94
* you may not use this file except in compliance with the License.
95
* You may obtain a copy of the License at
96
*
97
* http://www.apache.org/licenses/LICENSE-2.0
98
*
99
* Unless required by applicable law or agreed to in writing, software
100
* distributed under the License is distributed on an "AS IS" BASIS,
101
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
102
* See the License for the specific language governing permissions and
103
* limitations under the License.
104
*/
105

106
`
107
}
108

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.