idlize
/
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
16import nodeResolve from "@rollup/plugin-node-resolve";17import os from 'os';18import replace from '@rollup/plugin-replace';19import terser from "@rollup/plugin-terser";20import typescript from "@rollup/plugin-typescript";21import * as path from "path";22
23const platform = os.platform()24const isWindows = (platform === 'win32')25
26function crossPathRelative(from, to) {27if (isWindows) {28return path.relative(from, to).replace(/\\/g, '\\\\')29} else {30return path.relative(from, to)31}32}
33
34const mode = process.env.mode35const arch = process.env.arch36
37console.log(`rollup args: mode = ${mode}, arch = ${arch}`)38const generatedDir = `generated`39const arkoalaArkuiSrcDir = `${generatedDir}/${mode}/koalaui/arkoala-arkui/src`40const tsconfigFile = path.resolve(`tsconfig-${mode == 'subset' ? mode : 'generated'}.json`)41const outDir = path.resolve('lib')42
43const ENABLE_SOURCE_MAPS = true; // Enable for debugging44
45/** @type {import("rollup").RollupOptions} */
46export default {47input: `${arkoalaArkuiSrcDir}/main.ts`,48output: {49file: "./lib/main.js",50format: "commonjs",51sourcemap: ENABLE_SOURCE_MAPS,52sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {53// For some reason Rollup adds extra ../ to relativeSourcePath, remove it54let absolute = path.join(sourcemapPath, relativeSourcePath);55let relative = path.relative(path.dirname(sourcemapPath), absolute);56return relative57},58plugins: [59// terser()60],61banner: [62"#!/usr/bin/env node",63APACHE_LICENSE_HEADER()64].join("\n"),65},66external: [],67plugins: [68typescript({69outputToFilesystem: false,70module: "ESNext",71sourceMap: ENABLE_SOURCE_MAPS,72declarationMap: false,73declaration: false,74composite: false,75tsconfig: tsconfigFile,76filterRoot: '.'77}),78nodeResolve({79extensions: [".js", ".mjs", ".cjs", ".ts", ".cts", ".mts"]80}),81replace({82'LOAD_NATIVE': `require('${crossPathRelative(outDir, 'native/NativeBridgeNapi.node')}')`,83preventAssignment: true84})85]86}
87
88function APACHE_LICENSE_HEADER() {89return `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