1
+ import alias from '@rollup/plugin-alias' ;
1
2
import commonjs from '@rollup/plugin-commonjs' ;
2
3
import dynamicImportVars from '@rollup/plugin-dynamic-import-vars' ;
3
- import replace from '@rollup/plugin-replace' ;
4
4
import { nodeResolve } from '@rollup/plugin-node-resolve' ;
5
+ import replace from '@rollup/plugin-replace' ;
5
6
import terser from '@rollup/plugin-terser' ;
6
- import url from '@rollup/plugin-url'
7
- import svg from '@svgr/rollup'
8
- import dts from 'rollup-plugin-dts'
9
- import esbuild from 'rollup-plugin-esbuild'
7
+ import url from '@rollup/plugin-url' ;
8
+ import svg from '@svgr/rollup' ;
9
+ import dts from 'rollup-plugin-dts' ;
10
+ import esbuild from 'rollup-plugin-esbuild' ;
10
11
import postcss from "rollup-plugin-postcss" ;
11
12
12
- import pkg from './package.json' with { type : 'json' }
13
- const dependencies = Object . keys ( pkg . dependencies )
13
+ import path , { dirname } from 'node:path' ;
14
+ import { fileURLToPath } from 'node:url' ;
15
+
16
+ const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
17
+
18
+ import packageJson from './package.json' with { type : 'json' } ;
19
+ const dependencies = Object . keys ( packageJson . dependencies )
14
20
15
21
const banner = [
16
22
`/**` ,
17
- ` * ${ pkg . name } - v${ pkg . version } ` ,
23
+ ` * ${ packageJson . name } - v${ packageJson . version } ` ,
18
24
` * Compiled ${ ( new Date ( ) ) . toUTCString ( ) . replace ( / G M T / g, 'UTC' ) } ` ,
19
25
` *` ,
20
26
` * Copyright (c) ReachFive.` ,
@@ -24,18 +30,35 @@ const banner = [
24
30
` **/` ,
25
31
] . join ( '\n' ) ;
26
32
27
- // Ignore Luxon library's circular dependencies
28
- function onWarn ( message ) {
29
- if ( message . code === 'CIRCULAR_DEPENDENCY' || message . code === 'MODULE_LEVEL_DIRECTIVE' ) return ;
30
- console . warn ( message ) ;
33
+ /**
34
+ * Ignore Luxon library's circular dependencies
35
+ * @param {Partial<import('rollup').RollupLog> } warning
36
+ * @returns {void }
37
+ */
38
+ const onWarn = ( warning ) => {
39
+ if ( warning . code === 'CIRCULAR_DEPENDENCY' || warning . code === 'MODULE_LEVEL_DIRECTIVE' ) return ;
40
+ console . warn ( warning ) ;
31
41
}
32
42
43
+ /**
44
+ * @param {Partial<import('rollup').RollupOptions> } config
45
+ * @returns {import('rollup').RollupOptions }
46
+ */
33
47
const bundle = config => ( {
34
48
...config ,
35
49
input : 'src/index.ts' ,
36
50
} )
37
51
52
+ /** @type {import('rollup').InputPluginOption } */
38
53
const plugins = [
54
+ alias ( {
55
+ entries : [
56
+ {
57
+ find : / ^ @ \/ ( .* ) / ,
58
+ replacement : path . resolve ( __dirname , './src/$1' )
59
+ }
60
+ ]
61
+ } ) ,
39
62
replace ( {
40
63
preventAssignment : true ,
41
64
values : {
@@ -44,7 +67,7 @@ const plugins = [
44
67
} ) ,
45
68
nodeResolve ( {
46
69
browser : true ,
47
- extensions : [ '.jsx' , '.js' , '.json' ] ,
70
+ extensions : [ '.tsx' , '.ts' , '. jsx', '.js' , '.json' ] ,
48
71
preferBuiltins : true
49
72
} ) ,
50
73
commonjs ( { include : / n o d e _ m o d u l e s / } ) ,
@@ -61,29 +84,32 @@ const plugins = [
61
84
} ) ,
62
85
]
63
86
87
+ /** @type {import('rollup').RollupOptions[] } */
64
88
export default [
65
89
bundle ( {
66
90
plugins,
67
- external : dependencies . concat ( [ '@/lib/utils' ] ) ,
91
+ external : dependencies ,
68
92
output : [
69
93
{
70
94
banner,
71
- file : 'cjs/identity-ui.js' ,
95
+ file : packageJson . main ,
72
96
format : 'cjs' ,
73
97
sourcemap : true ,
74
98
inlineDynamicImports : true ,
75
99
} ,
76
100
{
77
101
banner,
78
- file : 'es/identity-ui.js' ,
102
+ file : packageJson . module ,
79
103
format : 'es' ,
80
104
sourcemap : true ,
81
105
inlineDynamicImports : true ,
82
106
} ,
83
107
{
84
- file : 'es/identity-ui. min.js',
108
+ file : packageJson . module . replace ( '.js' , '. min.js') ,
85
109
format : 'es' ,
86
- plugins : [ terser ( { output : { preamble : banner } } ) ] ,
110
+ plugins : [
111
+ terser ( { output : { preamble : banner } } )
112
+ ] ,
87
113
sourcemap : true ,
88
114
inlineDynamicImports : true ,
89
115
} ,
@@ -92,25 +118,31 @@ export default [
92
118
} ) ,
93
119
bundle ( {
94
120
plugins,
95
- external : [ '@/lib/utils' ] ,
121
+ external : [ ] ,
96
122
output : [
97
123
{
98
124
banner,
99
- file : ' umd/identity-ui.js' ,
125
+ file : packageJson . main . replace ( 'cjs/' , ' umd/' ) ,
100
126
format : 'umd' ,
101
127
name : 'reach5Widgets' ,
102
128
sourcemap : true ,
103
129
inlineDynamicImports : true ,
104
- globals : { '@reachfive/identity-core' : 'reach5' , "@/lib/utils" : "tw-cl-merge" } ,
130
+ globals : {
131
+ '@reachfive/identity-core' : 'reach5'
132
+ } ,
105
133
} ,
106
134
{
107
- file : ' umd/identity-ui. min.js',
135
+ file : packageJson . main . replace ( 'cjs/' , ' umd/' ) . replace ( '.js' , '. min.js') ,
108
136
format : 'umd' ,
109
137
name : 'reach5Widgets' ,
110
- plugins : [ terser ( { output : { preamble : banner } } ) ] ,
138
+ plugins : [
139
+ terser ( { output : { preamble : banner } } )
140
+ ] ,
111
141
sourcemap : true ,
112
142
inlineDynamicImports : true ,
113
- globals : { '@reachfive/identity-core' : 'reach5' , "@/lib/utils" : "tw-cl-merge" } ,
143
+ globals : {
144
+ '@reachfive/identity-core' : 'reach5'
145
+ } ,
114
146
} ,
115
147
] ,
116
148
onwarn : onWarn
@@ -121,7 +153,7 @@ export default [
121
153
] ,
122
154
output : {
123
155
banner,
124
- file : 'types/identity-ui.d.ts' ,
156
+ file : packageJson . types ,
125
157
format : 'es' ,
126
158
} ,
127
159
onwarn : onWarn
0 commit comments