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