@@ -14,11 +14,10 @@ import { polyfillNode } from 'esbuild-plugin-polyfill-node'
14
14
const require = createRequire ( import . meta. url )
15
15
const __dirname = dirname ( fileURLToPath ( import . meta. url ) )
16
16
const args = minimist ( process . argv . slice ( 2 ) )
17
- const target = args . _ [ 0 ] || 'vue'
17
+ const targets = args . _ || [ 'vue' ]
18
18
const format = args . f || 'global'
19
19
const prod = args . p || false
20
20
const inlineDeps = args . i || args . inline
21
- const pkg = require ( `../packages/${ target } /package.json` )
22
21
23
22
// resolve output
24
23
const outputFormat = format . startsWith ( 'global' )
@@ -31,101 +30,104 @@ const postfix = format.endsWith('-runtime')
31
30
? `runtime.${ format . replace ( / - r u n t i m e $ / , '' ) } `
32
31
: format
33
32
34
- const outfile = resolve (
35
- __dirname ,
36
- `../packages/${ target } /dist/${
37
- target === 'vue-compat' ? `vue` : target
38
- } .${ postfix } .${ prod ? `prod.` : `` } js`,
39
- )
40
- const relativeOutfile = relative ( process . cwd ( ) , outfile )
33
+ for ( const target of targets ) {
34
+ const pkg = require ( `../packages/${ target } /package.json` )
35
+ const outfile = resolve (
36
+ __dirname ,
37
+ `../packages/${ target } /dist/${
38
+ target === 'vue-compat' ? `vue` : target
39
+ } .${ postfix } .${ prod ? `prod.` : `` } js`,
40
+ )
41
+ const relativeOutfile = relative ( process . cwd ( ) , outfile )
41
42
42
- // resolve externals
43
- // TODO this logic is largely duplicated from rollup.config.js
44
- /** @type {string[] } */
45
- let external = [ ]
46
- if ( ! inlineDeps ) {
47
- // cjs & esm-bundler: external all deps
48
- if ( format === 'cjs' || format . includes ( 'esm-bundler' ) ) {
49
- external = [
50
- ...external ,
51
- ...Object . keys ( pkg . dependencies || { } ) ,
52
- ...Object . keys ( pkg . peerDependencies || { } ) ,
53
- // for @vue /compiler-sfc / server-renderer
54
- 'path' ,
55
- 'url' ,
56
- 'stream' ,
57
- ]
58
- }
43
+ // resolve externals
44
+ // TODO this logic is largely duplicated from rollup.config.js
45
+ /** @type {string[] } */
46
+ let external = [ ]
47
+ if ( ! inlineDeps ) {
48
+ // cjs & esm-bundler: external all deps
49
+ if ( format === 'cjs' || format . includes ( 'esm-bundler' ) ) {
50
+ external = [
51
+ ...external ,
52
+ ...Object . keys ( pkg . dependencies || { } ) ,
53
+ ...Object . keys ( pkg . peerDependencies || { } ) ,
54
+ // for @vue /compiler-sfc / server-renderer
55
+ 'path' ,
56
+ 'url' ,
57
+ 'stream' ,
58
+ ]
59
+ }
59
60
60
- if ( target === 'compiler-sfc' ) {
61
- const consolidatePkgPath = require . resolve (
62
- '@vue/consolidate/package.json' ,
63
- {
64
- paths : [ resolve ( __dirname , `../packages/${ target } /` ) ] ,
65
- } ,
66
- )
67
- const consolidateDeps = Object . keys (
68
- require ( consolidatePkgPath ) . devDependencies ,
69
- )
70
- external = [
71
- ...external ,
72
- ...consolidateDeps ,
73
- 'fs' ,
74
- 'vm' ,
75
- 'crypto' ,
76
- 'react-dom/server' ,
77
- 'teacup/lib/express' ,
78
- 'arc-templates/dist/es5' ,
79
- 'then-pug' ,
80
- 'then-jade' ,
81
- ]
61
+ if ( target === 'compiler-sfc' ) {
62
+ const consolidatePkgPath = require . resolve (
63
+ '@vue/consolidate/package.json' ,
64
+ {
65
+ paths : [ resolve ( __dirname , `../packages/${ target } /` ) ] ,
66
+ } ,
67
+ )
68
+ const consolidateDeps = Object . keys (
69
+ require ( consolidatePkgPath ) . devDependencies ,
70
+ )
71
+ external = [
72
+ ...external ,
73
+ ...consolidateDeps ,
74
+ 'fs' ,
75
+ 'vm' ,
76
+ 'crypto' ,
77
+ 'react-dom/server' ,
78
+ 'teacup/lib/express' ,
79
+ 'arc-templates/dist/es5' ,
80
+ 'then-pug' ,
81
+ 'then-jade' ,
82
+ ]
83
+ }
82
84
}
83
- }
84
- /** @type { Array<import('esbuild').Plugin> } */
85
- const plugins = [
86
- {
87
- name : 'log-rebuild' ,
88
- setup ( build ) {
89
- build . onEnd ( ( ) => {
90
- console . log ( `built: ${ relativeOutfile } ` )
91
- } )
85
+ /** @type { Array<import('esbuild').Plugin> } */
86
+ const plugins = [
87
+ {
88
+ name : 'log-rebuild' ,
89
+ setup ( build ) {
90
+ build . onEnd ( ( ) => {
91
+ console . log ( `built: ${ relativeOutfile } ` )
92
+ } )
93
+ } ,
92
94
} ,
93
- } ,
94
- ]
95
+ ]
95
96
96
- if ( format !== 'cjs' && pkg . buildOptions ?. enableNonBrowserBranches ) {
97
- plugins . push ( polyfillNode ( ) )
98
- }
97
+ if ( format !== 'cjs' && pkg . buildOptions ?. enableNonBrowserBranches ) {
98
+ plugins . push ( polyfillNode ( ) )
99
+ }
99
100
100
- esbuild
101
- . context ( {
102
- entryPoints : [ resolve ( __dirname , `../packages/${ target } /src/index.ts` ) ] ,
103
- outfile,
104
- bundle : true ,
105
- external,
106
- sourcemap : true ,
107
- format : outputFormat ,
108
- globalName : pkg . buildOptions ?. name ,
109
- platform : format === 'cjs' ? 'node' : 'browser' ,
110
- plugins,
111
- define : {
112
- __COMMIT__ : `"dev"` ,
113
- __VERSION__ : `"${ pkg . version } "` ,
114
- __DEV__ : prod ? `false` : `true` ,
115
- __TEST__ : `false` ,
116
- __BROWSER__ : String (
117
- format !== 'cjs' && ! pkg . buildOptions ?. enableNonBrowserBranches ,
118
- ) ,
119
- __GLOBAL__ : String ( format === 'global' ) ,
120
- __ESM_BUNDLER__ : String ( format . includes ( 'esm-bundler' ) ) ,
121
- __ESM_BROWSER__ : String ( format . includes ( 'esm-browser' ) ) ,
122
- __CJS__ : String ( format === 'cjs' ) ,
123
- __SSR__ : String ( format === 'cjs' || format . includes ( 'esm-bundler' ) ) ,
124
- __COMPAT__ : String ( target === 'vue-compat' ) ,
125
- __FEATURE_SUSPENSE__ : `true` ,
126
- __FEATURE_OPTIONS_API__ : `true` ,
127
- __FEATURE_PROD_DEVTOOLS__ : `false` ,
128
- __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__ : `false` ,
129
- } ,
130
- } )
131
- . then ( ctx => ctx . watch ( ) )
101
+ esbuild
102
+ . context ( {
103
+ entryPoints : [ resolve ( __dirname , `../packages/${ target } /src/index.ts` ) ] ,
104
+ outfile,
105
+ bundle : true ,
106
+ external,
107
+ sourcemap : true ,
108
+ format : outputFormat ,
109
+ globalName : pkg . buildOptions ?. name ,
110
+ platform : format === 'cjs' ? 'node' : 'browser' ,
111
+ plugins,
112
+ define : {
113
+ __COMMIT__ : `"dev"` ,
114
+ __VERSION__ : `"${ pkg . version } "` ,
115
+ __DEV__ : prod ? `false` : `true` ,
116
+ __TEST__ : `false` ,
117
+ __BROWSER__ : String (
118
+ format !== 'cjs' && ! pkg . buildOptions ?. enableNonBrowserBranches ,
119
+ ) ,
120
+ __GLOBAL__ : String ( format === 'global' ) ,
121
+ __ESM_BUNDLER__ : String ( format . includes ( 'esm-bundler' ) ) ,
122
+ __ESM_BROWSER__ : String ( format . includes ( 'esm-browser' ) ) ,
123
+ __CJS__ : String ( format === 'cjs' ) ,
124
+ __SSR__ : String ( format === 'cjs' || format . includes ( 'esm-bundler' ) ) ,
125
+ __COMPAT__ : String ( target === 'vue-compat' ) ,
126
+ __FEATURE_SUSPENSE__ : `true` ,
127
+ __FEATURE_OPTIONS_API__ : `true` ,
128
+ __FEATURE_PROD_DEVTOOLS__ : `false` ,
129
+ __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__ : `false` ,
130
+ } ,
131
+ } )
132
+ . then ( ctx => ctx . watch ( ) )
133
+ }
0 commit comments