rollup.JS 和“'this' 关键字等同于 'undefined'

rollup.JS and "'this' keyword is equivalent to 'undefined'

我正在尝试使用 Rollup.js 捆绑 Angular2 模块。 这是我的 rollup.config.vendor.js 文件:

import typescript from 'rollup-plugin-typescript2';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';

export default {
    entry: 'vendor.ts',
    dest: './Bundle/vendor.js',
    format: 'iife',
    moduleName: 'vendor',
    plugins: [
        typescript(),
        resolve({
            jsnext: true,
            main: true,
            browser: true
        }),
        commonjs({
            include: 'node_modules/rxjs/**',
        }),
    ]
}

它创建了一个捆绑的js,但在这个过程中它一直打印这种信息:

The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined
node_modules\@angular\forms\@angular\forms.es5.js (1:25)
1: var __extends = (this && this.__extends) || function (d, b) {
                            ^
2:     for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
3:     function __() { this.constructor = d; }

这是什么意思?
我是做错了什么还是应该是这样?

您可以安全地忽略这些警告,如 documentation 中所述,方法是将 onwarn 属性 添加到您的 rollup-config.js 文件:

onwarn: function(warning) {
    // Skip certain warnings

    // should intercept ... but doesn't in some rollup versions
    if ( warning.code === 'THIS_IS_UNDEFINED' ) { return; }

    // console.warn everything else
    console.warn( warning.message );
}

引用:

It overrides the default onwarn method in order to skip annoying messages about the AOT compiler's use of the this keyword.

您可以使用 context 选项并将其设置为 this:它避免将 this 重写为 undefined(实际上 this 是重写为... this).

查看 Rollup 文档: