当我发现我的捆绑包中有一个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;
}
答案 0 :(得分:0)
@JGoodgive
您可能会在创建的每个JavaScript文件上方添加自己的自定义许可证,因此将其捆绑在一起时,您的许可证文件应显示在JS代码上方。
/*! *****************************************************************************
Copyright (c) <Author>. All rights reserved.
<Custom license text here>
***************************************************************************** */
// Your JS code below your custom license
答案 1 :(得分:0)
Rollup将所需的所有内容捆绑到输出文件中。您看到的是tslib
模块中的Typescript助手。
您可以使用tslib
库导入来替换该代码(并摆脱MS许可证)。
添加到您的rollup.config.js
以下设置:external: ["tslib"]
。不幸的是,您需要在项目的依赖项(或peerDependencies)中添加tslib
模块。
检查以下对话以了解更多详细信息: https://github.com/ezolenko/rollup-plugin-typescript2/issues/58(关于外部设置)
https://github.com/ReactiveX/rxjs/issues/2436#issuecomment-371585945(关于依赖性vs peerDependency的问题)
以及有关助手的信息: https://mariusschulz.com/blog/external-helpers-library-in-typescript
答案 2 :(得分:0)
我在汇总配置中添加了rollup-plugin-terser,并将注释设置为false,因此所有注释均被删除。
...
import { terser } from 'rollup-plugin-terser';
...
plugins: [
...
terser({ format: { comments: false } }),
...
]