11import { defineConfig } from 'rollup' ;
2- import { fileURLToPath } from 'url' ;
3- import path from 'path' ;
2+ import typescript from 'rollup-plugin-typescript2' ;
3+ import externals from 'rollup-plugin-node-externals' ;
4+ import postcss from 'rollup-plugin-postcss' ;
45import vue from 'rollup-plugin-vue' ;
6+ import { nodeResolve } from '@rollup/plugin-node-resolve' ;
57import 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' ;
238
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- ] ;
9+ // common config settings for Vue package (only has index.ts, not internal.ts or server.ts)
10+ const input = [ 'src/index.ts' ] ;
11+ const esmOutputDir = 'dist/esm' ;
4012
4113/**
4214 * @type {import('rollup').OutputOptions }
4315 */
4416const cjsOutput = {
45- file : resolvePath ( './dist/index.cjs' ) ,
17+ dir : 'dist' ,
18+ entryFileNames : '[name].cjs' ,
19+ esModule : true ,
4620 format : 'cjs' ,
47- exports : 'named' ,
48- sourcemap : sourceMap ,
49- globals : { vue : 'Vue' }
21+ generatedCode : { reservedNamesAsProps : false } ,
22+ interop : 'auto' ,
23+ exports : 'named'
5024} ;
5125
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
26+ // shared plugins
27+ const vuePlugin = vue ( {
28+ compilerOptions : {
29+ isCustomElement : ( tag ) => tag . startsWith ( 'amplify-' )
30+ }
31+ } ) ;
32+
33+ // shared typescript configuration
34+ const typescriptConfig = {
35+ check : false , // disable type checking during build
36+ tsconfigOverride : {
37+ include : [ 'src/**/*' ] ,
38+ exclude : [ '**/__tests__/**/*' ] ,
39+ compilerOptions : {
40+ declaration : true ,
41+ declarationDir : 'dist' ,
42+ skipLibCheck : true ,
43+ noImplicitAny : false ,
44+ strictNullChecks : false
45+ }
46+ }
6047} ;
6148
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- } ) ;
49+ const config = defineConfig ( [
50+ // CJS config
51+ {
52+ input,
53+ output : cjsOutput ,
54+ external : [ 'vue' ] ,
55+ plugins : [
56+ externals ( { include : [ / n o d e _ m o d u l e s / , / ^ @ a w s - a m p l i f y / ] } ) ,
57+ nodeResolve ( ) ,
58+ commonjs ( ) ,
59+ vuePlugin ,
60+ postcss ( {
61+ extract : 'style.css' ,
62+ minimize : true ,
63+ sourceMap : false
64+ } ) ,
65+ typescript ( {
66+ ...typescriptConfig
67+ } ) ,
68+ ] ,
69+ } ,
70+ // ESM config
71+ {
72+ input,
73+ output : {
74+ dir : esmOutputDir ,
75+ format : 'es' ,
76+ entryFileNames : '[name].mjs' ,
77+ preserveModules : true ,
78+ preserveModulesRoot : 'src' ,
79+ exports : 'named'
80+ } ,
81+ external : [ 'vue' ] ,
82+ plugins : [
83+ externals ( { include : [ / n o d e _ m o d u l e s / , / ^ @ a w s - a m p l i f y / ] } ) ,
84+ nodeResolve ( {
85+ extensions : [ '.js' , '.ts' , '.vue' ]
86+ } ) ,
87+ commonjs ( ) ,
88+ vuePlugin ,
89+ postcss ( {
90+ extract : false ,
91+ inject : false ,
92+ sourceMap : false
93+ } ) ,
94+ typescript ( {
95+ ...typescriptConfig ,
96+ outDir : esmOutputDir ,
97+ tsconfigOverride : {
98+ ...typescriptConfig . tsconfigOverride ,
99+ compilerOptions : {
100+ ...typescriptConfig . tsconfigOverride . compilerOptions ,
101+ declaration : false
102+ }
103+ }
104+ } ) ,
105+ ] ,
106+ } ,
107+ ] ) ;
120108
121- export default config ;
109+ export default config ;
0 commit comments