From dc9ecce7bc68d7c20890fd9d03289fbcb28481d4 Mon Sep 17 00:00:00 2001 From: Aleksandr Veselov Date: Wed, 21 Aug 2024 15:29:49 +0300 Subject: [PATCH] Minify SDK plugin for release, add license --- arkoala/package.json | 1 + arkoala/tools/arkoala-transformer/index.ts | 15 ++++ .../arkoala-transformer/rollup.config.js | 90 ++++++++++++++----- 3 files changed, 82 insertions(+), 24 deletions(-) diff --git a/arkoala/package.json b/arkoala/package.json index 5b7d4081b..83ccca711 100644 --- a/arkoala/package.json +++ b/arkoala/package.json @@ -32,6 +32,7 @@ "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-node-resolve": "^13.2.0", "@rollup/plugin-replace": "^5.0.5", + "@rollup/plugin-terser": "^0.4.4", "@rollup/plugin-typescript": "^8.5.0", "rollup": "^2.70.1", "webpack": "^5.93.0", diff --git a/arkoala/tools/arkoala-transformer/index.ts b/arkoala/tools/arkoala-transformer/index.ts index 96db4bd1c..58502e52d 100644 --- a/arkoala/tools/arkoala-transformer/index.ts +++ b/arkoala/tools/arkoala-transformer/index.ts @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import memoPlugin from "@koalaui/compiler-plugin"; import { makeEtsExpander } from "@koalaui/ets-plugin"; import type * as ts from "typescript" diff --git a/arkoala/tools/arkoala-transformer/rollup.config.js b/arkoala/tools/arkoala-transformer/rollup.config.js index de82b8b6a..58c2e56ac 100644 --- a/arkoala/tools/arkoala-transformer/rollup.config.js +++ b/arkoala/tools/arkoala-transformer/rollup.config.js @@ -1,30 +1,72 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + const typescript = require("@rollup/plugin-typescript") const nodeResolve = require("@rollup/plugin-node-resolve").default const commonjs = require("@rollup/plugin-commonjs") const replace = require("@rollup/plugin-replace") +const terser = require("@rollup/plugin-terser") +const { defineConfig } = require("rollup") + +const license = `/** + * @license + * Copyright (c) ${new Date().getFullYear()} Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */` + +module.exports = (argv) => { + const RELEASE = argv.release ?? false; + + delete argv.release -/** @type { import("rollup").RollupOptions } */ -module.exports = { - input: "index.ts", - output: { - file: "arkoala-plugin.js", - format: "commonjs", - exports: "default", - }, - external: ["typescript", "ohos-typescript"], - plugins: [ - replace({ - values: { - 'ohos-typescript': 'typescript', - }, - preventAssignment: true, - }), - typescript({ - module: "esnext" - }), - nodeResolve({ - - }), - commonjs(), - ] + return defineConfig({ + input: "index.ts", + output: { + file: "arkoala-plugin.js", + format: "commonjs", + exports: "default", + plugins: [ + RELEASE ? terser() : null, + ], + banner: license + }, + external: ["typescript", "ohos-typescript"], + plugins: [ + replace({ + values: { + 'ohos-typescript': 'typescript', + }, + preventAssignment: true, + }), + typescript({ + module: "esnext" + }), + nodeResolve({ + + }), + commonjs(), + ] + }) } \ No newline at end of file -- Gitee