transform/transformBundle can return null/undefined

I did not find it explicitly in documentation, but here is the code:
https://github.com/rollup/rollup/blob/master/src/utils/transform.js#L78
https://github.com/rollup/rollup/blob/master/src/utils/transformBundle.js#L12
This commit is contained in:
Christian Svensson
2017-11-18 02:54:58 +01:00
parent 78bf7ac1d6
commit 3be84fe1aa
2 changed files with 13 additions and 2 deletions
+2 -2
View File
@@ -137,9 +137,9 @@ export interface Plugin {
*/
resolveId?(importee: string, importer: string | undefined): string | null | undefined | false | 0 | ''
/** A module transformer function */
transform?(this: TransformContext, source: string, id: string): string | { code: string, map: SourceMap }
transform?(this: TransformContext, source: string, id: string): string | null | undefined | { code: string, map: SourceMap }
/** A bundle transformer function */
transformBundle?(source: string, options: { format: Format }): string | { code: string, map: SourceMap }
transformBundle?(source: string, options: { format: Format }): string | null | undefined | { code: string, map: SourceMap }
/** Function hook called when bundle.generate() is being executed. */
ongenerate?(options: GenerateOptions, bundle: Bundle): void
/** Function hook called when bundle.write() is being executed, after the file has been written to disk. */
+11
View File
@@ -14,12 +14,23 @@ const plugin: Plugin = {
transform(source, id) {
if (id === 'rxjs') {
this.error(new Error(`Don't import this directly`))
return null
}
const indexOfQuote = source.indexOf('"')
if (indexOfQuote >= 0) {
this.warn(`Prefer ' over " for strings`, indexOfQuote)
return undefined
}
return source
},
transformBundle(source, options) {
if (options.format === 'iife') {
return `window.nonModule = true\n${source}`
} else if (options.format === 'cjs') {
return null
}
return undefined
}
}