7

我正在写几个小演示来向同事解释装饰器(在打字稿中),当我注意到我的包有一个微软版权声明,让我的整个文件对所有人免费(并且由 MS 制作)。

应该如何有效地处理这个问题(如果我创建的东西不是免费的)?

我使用 Typescript 3.1 编译和汇总以进行捆绑。

代码:

import { isNotUndefined, isNotNullOrUndefined } from "goodcore/Test";

function deprecated<S>(instead?: string, message?: string) {
    // Logic removed for brevity...
}

class Car {
    @deprecated()
    public turnIgnitionKey() {
        this.start();
    }
    public pressStartButton() {
        this.start();
    }
    private start() {
        console.log("Running!");
    }
}

let car = new Car();
car.turnIgnitionKey();
car.pressStartButton();

和捆绑开始(最后一个函数是我的,之前的函数是 MS):

'use strict';

/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
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

THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.

See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */

function __decorate(decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
}

function __metadata(metadataKey, metadataValue) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}

function isNullOrUndefined(arg) {
    return arg === undefined || arg === null;
}
4

3 回答 3

11

我在我的汇总配置中添加了 rollup-plugin-terser 并将评论设置为 false,以便删除所有评论。

...
import { terser } from 'rollup-plugin-terser';
...
plugins: [
    ...
    terser({ format: { comments: false } }),
    ...
]
于 2020-10-20T02:44:36.987 回答
5

Rollup 将所需的所有内容捆绑到输出文件中。您看到的是来自tslib模块的 Typescript 助手。

tslib您可以用库导入替换该代码(并摆脱 MS 许可证) 。

添加到您的rollup.config.js以下设置:external: ["tslib"]. 不幸的是,您需要将tslib模块添加到项目的依赖项(或 peerDependencies)中。

检查以下对话以获取更多详细信息: https ://github.com/ezolenko/rollup-plugin-typescript2/issues/58 (关于外部设置)

https://github.com/ReactiveX/rxjs/issues/2436#issuecomment-371585945(关于依赖与 peerDependency 的问题)

在这里关于助手: https ://mariusschulz.com/blog/external-helpers-library-in-typescript

于 2019-09-05T14:35:08.383 回答
0

@JGoodgive,

您可能会在您创建的每个 JavaScript 文件上方添加您自己的自定义许可,因此当它们捆绑在一起时,您的许可文件应该显示在您的 JS 代码上方。

/*! *****************************************************************************
Copyright (c) <Author>. All rights reserved.
<Custom license text here>
***************************************************************************** */

// Your JS code below your custom license 
于 2019-05-10T13:24:09.277 回答