1+ import { defineConfig } from 'rollup' ;
2+ import { fileURLToPath } from 'url' ;
3+ import path from 'path' ;
4+ import vue from 'rollup-plugin-vue' ;
5+ import commonjs from '@rollup/plugin-commonjs' ;
6+ import resolve from '@rollup/plugin-node-resolve' ;
7+ import postcss from 'rollup-plugin-postcss' ;
8+ import dynamicImportVars from '@rollup/plugin-dynamic-import-vars' ;
9+ import externals from 'rollup-plugin-node-externals' ;
10+ import esbuild from 'rollup-plugin-esbuild' ;
11+ import typescript2 from 'rollup-plugin-typescript2' ;
12+
13+ // ES Module equivalent for __dirname
14+ const __filename = fileURLToPath ( import . meta. url ) ;
15+ const __dirname = path . dirname ( __filename ) ;
16+
17+ const resolvePath = ( str ) => path . resolve ( __dirname , str ) ;
18+
19+ // common config settings
20+ const input = 'src/index.ts' ;
21+ const sourceMap = true ;
22+ const tsconfig = 'tsconfig.dist.json' ;
23+
24+ // External dependencies that shouldn't be bundled
25+ const external = [
26+ '@aws-amplify/auth' ,
27+ '@aws-amplify/core' ,
28+ '@aws-amplify/core/internals/utils' ,
29+ 'aws-amplify' ,
30+ 'aws-amplify/auth' ,
31+ 'aws-amplify/core' ,
32+ 'aws-amplify/utils' ,
33+ 'vue' ,
34+ 'qrcode' ,
35+ 'nanoid' ,
36+ '@vueuse/core' ,
37+ '@xstate/vue' ,
38+ 'xstate'
39+ ] ;
40+
41+ /**
42+ * @type {import('rollup').OutputOptions }
43+ */
44+ const cjsOutput = {
45+ file : resolvePath ( './dist/index.cjs' ) ,
46+ format : 'cjs' ,
47+ exports : 'named' ,
48+ sourcemap : sourceMap ,
49+ globals : { vue : 'Vue' }
50+ } ;
51+
52+ /**
53+ * @type {import('rollup').OutputOptions }
54+ */
55+ const esmOutput = {
56+ file : resolvePath ( './dist/index.js' ) ,
57+ format : 'es' ,
58+ exports : 'named' ,
59+ sourcemap : sourceMap
60+ } ;
61+
62+ // Following React's approach with Vue-specific additions
63+ const config = defineConfig ( {
64+ input : resolvePath ( input ) ,
65+ output : [ cjsOutput , esmOutput ] ,
66+ external,
67+ plugins : [
68+ // Exclude test files and node_modules
69+ externals ( {
70+ exclude : [ 'tslib' ] ,
71+ } ) ,
72+ resolve ( {
73+ extensions : [ '.js' , '.ts' , '.vue' ]
74+ } ) ,
75+ commonjs ( ) ,
76+ // Vue-specific plugins
77+ vue ( {
78+ preprocessStyles : true ,
79+ template : {
80+ isProduction : true
81+ }
82+ } ) ,
83+ postcss ( {
84+ extract : 'style.css' ,
85+ minimize : true ,
86+ sourceMap : true
87+ } ) ,
88+ // Use typescript2 for proper declaration file generation
89+ typescript2 ( {
90+ check : false ,
91+ tsconfig : resolvePath ( tsconfig ) ,
92+ tsconfigOverride : {
93+ compilerOptions : {
94+ sourceMap : true ,
95+ declaration : true ,
96+ declarationMap : true ,
97+ outDir : resolvePath ( './dist' ) ,
98+ declarationDir : resolvePath ( './dist' )
99+ } ,
100+ exclude : [
101+ "**/__tests__/**" ,
102+ "**/__mocks__/**" ,
103+ "**/*.spec.ts" ,
104+ "global-spec.ts" ,
105+ "node_modules"
106+ ]
107+ }
108+ } ) ,
109+ // Use esbuild for faster JavaScript transpilation
110+ esbuild ( {
111+ include : / \. [ j t ] s x ? $ / ,
112+ exclude : / n o d e _ m o d u l e s | _ _ t e s t s _ _ | _ _ m o c k s _ _ / ,
113+ sourceMap : true ,
114+ target : 'es2015' ,
115+ tsconfig : resolvePath ( tsconfig )
116+ } ) ,
117+ dynamicImportVars
118+ ]
119+ } ) ;
120+
121+ export default config ;
0 commit comments