我尝试使用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; }
这是什么意思?
我做错了什么,或者它应该是这样的?
答案 0 :(得分:12)
您可以安全地忽略这些警告,如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 );
}
引用:
它会覆盖默认的onwarn方法,以便跳过有关AOT编译器使用this关键字的恼人消息。
答案 1 :(得分:0)
您可以使用context
选项并将其设置为this
:这样可以避免将this
重写为undefined
(实际上this
被重写为... this
)。
请参阅汇总文档: