【问题标题】:How to handle Copyright notice in javascript bundle?如何处理 javascript 包中的版权声明?
【发布时间】:2018-10-17 07:55:34
【问题描述】:

我正在写几个小演示来向同事解释装饰器(在打字稿中),当我注意到我的捆绑包有一个 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();

和捆绑开始(最后一个函数是我的,之前的函数是 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;
}

【问题讨论】:

    标签: typescript bundling-and-minification rollupjs copyright-display


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

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

      将以下设置添加到您的rollup.config.jsexternal: ["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

      【讨论】:

        【解决方案3】:

        @JGoodgive,

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

        /*! *****************************************************************************
        Copyright (c) <Author>. All rights reserved.
        <Custom license text here>
        ***************************************************************************** */
        
        // Your JS code below your custom license 
        

        【讨论】:

        • 这在这里不起作用,可以替代external: ["tslib"]?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-13
        • 1970-01-01
        • 2020-04-23
        • 2013-10-22
        相关资源
        最近更新 更多