Skip to content

Commit ec49996

Browse files
committed
build(bezier-icons): refactor rollup config
1 parent 338e2ed commit ec49996

File tree

1 file changed

+55
-58
lines changed

1 file changed

+55
-58
lines changed

packages/bezier-icons/rollup.config.mjs

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,30 @@ const entryModuleContent = iconImportLines
6363
.concat(exports)
6464
.join('\n')
6565

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
6868
export declare type BezierIcon = IconSource & { __type: 'BezierIcon' }
6969
7070
export declare function isBezierIcon(arg: unknown): arg is BezierIcon
7171
export declare function createBezierIcon(icon: IconSource): BezierIcon
7272
7373
export declare type IconName = ${iconNames.join(' | ')}
74-
7574
/**
7675
* @deprecated If you import this module, all icons are bundled, so please import and use the individual icons.
7776
* @example
7877
* import { AllIcon } from '@channel.io/bezier-icons'
7978
*/
8079
export declare const icons: Record<IconName, BezierIcon>
81-
`.trim()
8280
83-
const entryTypesContent = `${iconUtilTypes}\n\n${iconComponentTypes.join('\n')}\n`
81+
${iconComponentTypes.join('\n')}
82+
`.trim()
8483

8584
/**
8685
* @type {import('rollup').PluginImpl}
8786
*/
8887
function emitFile({ fileName, source }) {
8988
return {
90-
name: 'emit-file',
89+
name: 'emitFile',
9190
buildEnd() {
9291
if (source.length === 0) {
9392
this.warn('source content is empty')
@@ -157,7 +156,7 @@ function svgBuild(options = {}) {
157156
const optimizedSvgs = []
158157

159158
return {
160-
name: 'buildSvg',
159+
name: 'svgBuild',
161160
async transform(code, id) {
162161
if (!filter(id) || !id.endsWith('.svg')) { return null }
163162

@@ -242,56 +241,54 @@ function manualChunks(id) {
242241
return undefined
243242
}
244243

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` }),
247272
/**
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.
249274
*/
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

Comments
 (0)