@@ -63,31 +63,30 @@ const entryModuleContent = iconImportLines
63
63
. concat ( exports )
64
64
. join ( '\n' )
65
65
66
- const iconUtilTypes = `
67
- export declare type IconSource = React.FunctionComponent<React. SVGProps<SVGSVGElement>>
66
+ const entryTypesContent = `
67
+ export declare type IconSource = (props: SVGProps<SVGSVGElement>) => JSX.Element
68
68
export declare type BezierIcon = IconSource & { __type: 'BezierIcon' }
69
69
70
70
export declare function isBezierIcon(arg: unknown): arg is BezierIcon
71
71
export declare function createBezierIcon(icon: IconSource): BezierIcon
72
72
73
73
export declare type IconName = ${ iconNames . join ( ' | ' ) }
74
-
75
74
/**
76
75
* @deprecated If you import this module, all icons are bundled, so please import and use the individual icons.
77
76
* @example
78
77
* import { AllIcon } from '@channel.io/bezier-icons'
79
78
*/
80
79
export declare const icons: Record<IconName, BezierIcon>
81
- ` . trim ( )
82
80
83
- const entryTypesContent = `${ iconUtilTypes } \n\n${ iconComponentTypes . join ( '\n' ) } \n`
81
+ ${ iconComponentTypes . join ( '\n' ) }
82
+ ` . trim ( )
84
83
85
84
/**
86
85
* @type {import('rollup').PluginImpl }
87
86
*/
88
87
function emitFile ( { fileName, source } ) {
89
88
return {
90
- name : 'emit-file ' ,
89
+ name : 'emitFile ' ,
91
90
buildEnd ( ) {
92
91
if ( source . length === 0 ) {
93
92
this . warn ( 'source content is empty' )
@@ -157,7 +156,7 @@ function svgBuild(options = {}) {
157
156
const optimizedSvgs = [ ]
158
157
159
158
return {
160
- name : 'buildSvg ' ,
159
+ name : 'svgBuild ' ,
161
160
async transform ( code , id ) {
162
161
if ( ! filter ( id ) || ! id . endsWith ( '.svg' ) ) { return null }
163
162
@@ -242,56 +241,54 @@ function manualChunks(id) {
242
241
return undefined
243
242
}
244
243
245
- export default defineConfig ( [
246
- {
244
+ export default defineConfig ( {
245
+ /**
246
+ * Instead of the actual src/index.ts, use a virtual entry point via virtual plugin.
247
+ */
248
+ input : 'src/index.ts' ,
249
+ output : [
250
+ {
251
+ dir : 'dist' ,
252
+ format : 'cjs' ,
253
+ entryFileNames : '[name].js' ,
254
+ chunkFileNames : '[name].js' ,
255
+ interop,
256
+ manualChunks,
257
+ } ,
258
+ {
259
+ dir : 'dist' ,
260
+ format : 'esm' ,
261
+ entryFileNames : '[name].mjs' ,
262
+ chunkFileNames : '[name].mjs' ,
263
+ interop,
264
+ manualChunks,
265
+ } ,
266
+ ] ,
267
+ external : [ 'react' ] ,
268
+ plugins : [
269
+ virtual ( { 'src/index.ts' : entryModuleContent } ) ,
270
+ typescript ( ) ,
271
+ svgBuild ( { include : `${ iconBasePath } /*.svg` } ) ,
247
272
/**
248
- * Instead of the actual src/index.ts, use a virtual entry point via virtual plugin .
273
+ * Module resolution is not working well inside the virtual module, so use the alias plugin to resolve the module manually .
249
274
*/
250
- input : 'src/index.ts' ,
251
- output : [
252
- {
253
- dir : 'dist' ,
254
- format : 'cjs' ,
255
- entryFileNames : '[name].js' ,
256
- chunkFileNames : '[name].js' ,
257
- interop,
258
- manualChunks,
259
- } ,
260
- {
261
- dir : 'dist' ,
262
- format : 'esm' ,
263
- entryFileNames : '[name].mjs' ,
264
- chunkFileNames : '[name].mjs' ,
265
- interop,
266
- manualChunks,
267
- } ,
268
- ] ,
269
- external : [ 'react' ] ,
270
- plugins : [
271
- virtual ( { 'src/index.ts' : entryModuleContent } ) ,
272
- typescript ( ) ,
273
- svgBuild ( { include : `${ iconBasePath } /*.svg` } ) ,
274
- /**
275
- * The module is not resolving well, so use the alias plugin to resolve the module.
276
- */
277
- alias ( {
278
- entries : [ {
279
- find : config . input . utils ,
280
- replacement : utilBasePath ,
281
- } ] ,
282
- } ) ,
283
- babel ( {
284
- exclude : 'node_modules/**' ,
285
- extensions : [ '.js' , '.jsx' , '.ts' , '.tsx' , '.svg' ] ,
286
- envName : 'production' ,
287
- babelHelpers : 'bundled' ,
288
- } ) ,
289
- emitFile ( {
290
- fileName : 'index.d.ts' ,
291
- source : entryTypesContent ,
292
- } ) ,
293
- terser ( ) ,
294
- visualizer ( ) ,
295
- ] ,
296
- } ,
297
- ] )
275
+ alias ( {
276
+ entries : [ {
277
+ find : config . input . utils ,
278
+ replacement : utilBasePath ,
279
+ } ] ,
280
+ } ) ,
281
+ babel ( {
282
+ exclude : 'node_modules/**' ,
283
+ extensions : [ '.js' , '.jsx' , '.ts' , '.tsx' , '.svg' ] ,
284
+ envName : 'production' ,
285
+ babelHelpers : 'bundled' ,
286
+ } ) ,
287
+ emitFile ( {
288
+ fileName : 'index.d.ts' ,
289
+ source : entryTypesContent ,
290
+ } ) ,
291
+ terser ( ) ,
292
+ visualizer ( ) ,
293
+ ] ,
294
+ } )
0 commit comments