@@ -9,62 +9,70 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url))
9
9
10
10
import pkg from '../package.json' assert { type : 'json ' } ;
11
11
12
- const vueTarget = '3' ;
13
- const outputFormat = 'module' ;
12
+
14
13
const genSourcemap = false ;
15
14
15
+ async function configFactory ( { name, vueTarget, libraryTargetModule } ) {
16
16
17
- let vueVersion ; // expected vue version
18
- switch ( vueTarget ) {
19
- case '2' :
20
- vueVersion = ( await import ( 'vue-template-compiler/package.json' , { assert : { type : 'json' } } ) ) . default . version ;
21
- break ;
22
- case '3' :
23
- vueVersion = ( await import ( '@vue/compiler-sfc/package.json' , { assert : { type : 'json' } } ) ) . default . version ;
24
- break ;
25
- default :
26
- throw new Error ( `invalid vueTarget: ${ vueTarget } ` )
17
+ let vueVersion ; // expected vue version
18
+ switch ( vueTarget ) {
19
+ case '2' :
20
+ vueVersion = ( await import ( 'vue-template-compiler/package.json' , { assert : { type : 'json' } } ) ) . default . version ;
21
+ break ;
22
+ case '3' :
23
+ vueVersion = ( await import ( '@vue/compiler-sfc/package.json' , { assert : { type : 'json' } } ) ) . default . version ;
24
+ break ;
25
+ default :
26
+ throw new Error ( `invalid vueTarget: ${ vueTarget } ` )
27
+ }
28
+
29
+ /**
30
+ * @type {import('rollup').RollupOptions }
31
+ */
32
+ const config = {
33
+ input : './src/index.ts' ,
34
+ output : {
35
+ file : `dist/vue${ vueTarget } -sfc-loader-node.${ libraryTargetModule ? 'mjs' : 'js' } ` ,
36
+ format : libraryTargetModule ? 'module' : 'commonjs' ,
37
+ } ,
38
+ plugins : [
39
+ replace ( {
40
+ preventAssignment : true ,
41
+ values : {
42
+ 'process.env.GEN_SOURCEMAP' : JSON . stringify ( genSourcemap ) ,
43
+ 'process.env.VERSION' : JSON . stringify ( pkg . version ) ,
44
+ 'process.env.VUE_VERSION' : JSON . stringify ( vueVersion ) ,
45
+ } ,
46
+ } ) ,
47
+ alias ( {
48
+ entries : [
49
+ { find : './createSFCModule' , replacement : `./createVue${ vueTarget } SFCModule` } ,
50
+ ]
51
+ } ) ,
52
+ typescript ( {
53
+ compilerOptions : {
54
+ target : 'ES2017' , // keep async/await
55
+ allowSyntheticDefaultImports : true ,
56
+ }
57
+ } ) , // beware: order is important !
58
+ terser ( {
59
+ compress : false ,
60
+ mangle : false ,
61
+ output : {
62
+ comments : false ,
63
+ beautify : true ,
64
+ } ,
65
+ } ) ,
66
+ ] ,
67
+ } ;
68
+ return config ;
27
69
}
28
70
29
71
30
- /**
31
- * @type {import('rollup').RollupOptions }
32
- */
33
- const config = {
34
- input : './src/index.ts' ,
35
- output : {
36
- file : `dist/vue${ vueTarget } -sfc-loader-node.${ outputFormat === 'module' ? 'mjs' : 'js' } ` ,
37
- format : outputFormat ,
38
- } ,
39
- plugins : [
40
- replace ( {
41
- preventAssignment : true ,
42
- values : {
43
- 'process.env.GEN_SOURCEMAP' : JSON . stringify ( genSourcemap ) ,
44
- 'process.env.VERSION' : JSON . stringify ( pkg . version ) ,
45
- 'process.env.VUE_VERSION' : JSON . stringify ( vueVersion ) ,
46
- } ,
47
- } ) ,
48
- alias ( {
49
- entries : [
50
- { find : './createSFCModule' , replacement : `./createVue${ vueTarget } SFCModule` } ,
51
- ]
52
- } ) ,
53
- typescript ( {
54
- compilerOptions : {
55
- target : 'ES2017' , // keep async/await
56
- allowSyntheticDefaultImports : true ,
57
- }
58
- } ) , // beware: order is important !
59
- terser ( {
60
- compress : false ,
61
- mangle : false ,
62
- output : {
63
- comments : false ,
64
- beautify : true ,
65
- } ,
66
- } ) ,
67
- ] ,
68
- } ;
69
72
70
- export default config ;
73
+ export default [
74
+ await configFactory ( { name : 'vue2' , vueTarget : '2' , libraryTargetModule : false } ) ,
75
+ await configFactory ( { name : 'vue2esm' , vueTarget : '2' , libraryTargetModule : true } ) ,
76
+ await configFactory ( { name : 'vue3' , vueTarget : '3' , libraryTargetModule : false } ) ,
77
+ await configFactory ( { name : 'vue3esm' , vueTarget : '3' , libraryTargetModule : true } ) ,
78
+ ] ;
0 commit comments