如何处理javascript包中的版权声明?

JGo*_*ive 6 bundling-and-minification typescript copyright-display rollupjs

我正在编写几个小演示来向同事解释装饰器(在打字稿中),当我注意到我的捆绑包有一个 Microsoft 版权声明,这种通知使我的整个文件对所有人免费(并且由 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();
Run Code Online (Sandbox Code Playgroud)

和 bundle 开始(最后一个函数是我的,之前的那些是 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;
}
Run Code Online (Sandbox Code Playgroud)

ian*_*ian 8

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

...
import { terser } from 'rollup-plugin-terser';
...
plugins: [
    ...
    terser({ format: { comments: false } }),
    ...
]
Run Code Online (Sandbox Code Playgroud)


小智 5

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

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

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

检查以下对话以了解更多详细信息: 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