# this.warn

类型:
(warning: string | RollupWarning, position?: number | { column: number; line: number }) => void

使用此方法将为构建排队警告。这些警告将像内部生成的警告一样由 CLI 打印(除了插件名称),或者被自定义的 onwarn 处理程序捕获。

warning 参数可以是一个 string 或一个对象,其中至少有一个 message 属性:

this.warn('hmm...');
// 等价于
this.warn({ message: 'hmm...' });

如果需要向警告对象添加其他属性,请使用第二种形式。Rollup 将使用包含插件名称、code(PLUGIN_WARNING)和 id(正在转换的文件)属性的 plugin 属性增强警告对象。

position 参数是引发警告的字符索引。如果存在,Rollup 将使用 pos、loc(标准的 { file, line, column } 对象)和 frame(显示错误的代码片段)增强警告对象。

Last Updated: 6/14/2023, 8:56:23 AM