File tree Expand file tree Collapse file tree 3 files changed +11
-6
lines changed Expand file tree Collapse file tree 3 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ export type FileContentSpecifier = string | FileContentSetter;
59
59
export type FileContentSetter = (
60
60
id : string ,
61
61
originalCode : string
62
- ) => SourceDescription ;
62
+ ) => string | SourceDescription ;
63
63
```
64
64
65
65
details:
@@ -93,12 +93,12 @@ Values are handled in the same way as [`include`](#include)
93
93
94
94
### ` content `
95
95
96
- Type: ` String ` | ` (id: string, originalCode: string) => SourceDescription `
96
+ Type: ` String ` | ` (id: string, originalCode: string) => string | SourceDescription `
97
97
** Mandatory**
98
98
99
99
Specifies the content of the imported module.
100
100
101
- For functions, the string value returned by the function will be passed to Rollup to change the content of the file
101
+ For functions, the string or SourceDescription value returned by the function will be passed to Rollup to change the content of the file
102
102
The [ plugin context] ( https://rollupjs.org/plugin-development/#plugin-context ) will be ` this ` for the function
103
103
104
104
> ` SourceDescription ` is a rollup interface (see more in [ Rollup Docs] ( https://rollupjs.org/plugin-development/#transform ) ):
Original file line number Diff line number Diff line change @@ -17,4 +17,4 @@ export type FileContentSpecifier = string | FileContentSetter;
17
17
export type FileContentSetter = (
18
18
id : string ,
19
19
originalCode : string
20
- ) => SourceDescription ;
20
+ ) => string | SourceDescription ;
Original file line number Diff line number Diff line change @@ -47,15 +47,20 @@ export function getFileContent<self>(
47
47
} ;
48
48
} else if ( typeof specifier === 'function' ) {
49
49
const ret = specifier . call ( _this , id , originalCode ) ;
50
- if ( typeof ret === 'object' ) {
50
+ if ( typeof ret === 'string' ) {
51
+ return {
52
+ code : ret ,
53
+ map : null ,
54
+ } ;
55
+ } else if ( typeof ret === 'object' ) {
51
56
if ( typeof ret . code !== 'string' )
52
57
throw new TypeError (
53
58
'The returned SourceDescription of the content function must have a code property'
54
59
) ;
55
60
return ret ;
56
61
} else
57
62
throw new TypeError (
58
- 'The return value of the content function must be SourceDescription'
63
+ 'The return value of the content function must be string | SourceDescription'
59
64
) ;
60
65
} else
61
66
throw new TypeError (
You can’t perform that action at this time.
0 commit comments