@@ -15,6 +15,12 @@ import alias from '@rollup/plugin-alias'
1515import { entries } from './scripts/aliases.js'
1616import { inlineEnums } from './scripts/inline-enums.js'
1717import { minify as minifySwc } from '@swc/core'
18+ import {
19+ resolveCJSIgnores ,
20+ resolveDefines ,
21+ resolveEntryFile ,
22+ resolveExternal as resolveExternalShared ,
23+ } from './scripts/build-shared.js'
1824
1925/**
2026 * @template T
@@ -32,7 +38,6 @@ const require = createRequire(import.meta.url)
3238const __dirname = fileURLToPath ( new URL ( '.' , import . meta. url ) )
3339
3440const masterVersion = require ( './package.json' ) . version
35- const consolidatePkg = require ( '@vue/consolidate/package.json' )
3641
3742const privatePackages = fs . readdirSync ( 'packages-private' )
3843const pkgBase = privatePackages . includes ( process . env . TARGET )
@@ -156,54 +161,19 @@ function createConfig(format, output, plugins = []) {
156161 output . name = packageOptions . name
157162 }
158163
159- let entryFile = / r u n t i m e $ / . test ( format ) ? `src/runtime.ts` : `src/index.ts`
160-
161- // the compat build needs both default AND named exports. This will cause
162- // Rollup to complain for non-ESM targets, so we use separate entries for
163- // esm vs. non-esm builds.
164- if ( isCompatPackage && ( isBrowserESMBuild || isBundlerESMBuild ) ) {
165- entryFile = / r u n t i m e $ / . test ( format )
166- ? `src/esm-runtime.ts`
167- : `src/esm-index.ts`
168- }
164+ // Use shared function for entry file resolution
165+ const entryFile = resolveEntryFile ( format , isCompatPackage )
169166
170167 function resolveDefine ( ) {
171- /** @type {Record<string, string> } */
172- const replacements = {
173- __COMMIT__ : `"${ process . env . COMMIT } "` ,
174- __VERSION__ : `"${ masterVersion } "` ,
175- // this is only used during Vue's internal tests
176- __TEST__ : `false` ,
177- // If the build is expected to run directly in the browser (global / esm builds)
178- __BROWSER__ : String ( isBrowserBuild ) ,
179- __GLOBAL__ : String ( isGlobalBuild ) ,
180- __ESM_BUNDLER__ : String ( isBundlerESMBuild ) ,
181- __ESM_BROWSER__ : String ( isBrowserESMBuild ) ,
182- // is targeting Node (SSR)?
183- __CJS__ : String ( isCJSBuild ) ,
184- // need SSR-specific branches?
185- __SSR__ : String ( ! isGlobalBuild ) ,
186-
187- // 2.x compat build
188- __COMPAT__ : String ( isCompatBuild ) ,
189-
190- // feature flags
191- __FEATURE_SUSPENSE__ : `true` ,
192- __FEATURE_OPTIONS_API__ : isBundlerESMBuild
193- ? `__VUE_OPTIONS_API__`
194- : `true` ,
195- __FEATURE_PROD_DEVTOOLS__ : isBundlerESMBuild
196- ? `__VUE_PROD_DEVTOOLS__`
197- : `false` ,
198- __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__ : isBundlerESMBuild
199- ? `__VUE_PROD_HYDRATION_MISMATCH_DETAILS__`
200- : `false` ,
201- }
202-
203- if ( ! isBundlerESMBuild ) {
204- // hard coded dev/prod builds
205- replacements . __DEV__ = String ( ! isProductionBuild )
206- }
168+ // Use shared function for base defines
169+ const replacements = resolveDefines ( {
170+ pkg,
171+ format,
172+ target : process . env . TARGET ,
173+ prod : isProductionBuild ,
174+ version : masterVersion ,
175+ commit : process . env . COMMIT || 'dev' ,
176+ } )
207177
208178 // allow inline overrides like
209179 //__RUNTIME_COMPILE__=true pnpm build runtime-core
@@ -255,50 +225,21 @@ function createConfig(format, output, plugins = []) {
255225 }
256226
257227 function resolveExternal ( ) {
258- const treeShakenDeps = [
259- 'source-map-js' ,
260- '@babel/parser' ,
261- 'estree-walker' ,
262- 'entities/lib/decode.js' ,
263- ]
264-
265- if ( isGlobalBuild || isBrowserESMBuild || isCompatPackage ) {
266- if ( ! packageOptions . enableNonBrowserBranches ) {
267- // normal browser builds - non-browser only imports are tree-shaken,
268- // they are only listed here to suppress warnings.
269- return treeShakenDeps
270- }
271- } else {
272- // Node / esm-bundler builds.
273- // externalize all direct deps unless it's the compat build.
274- return [
275- ...Object . keys ( pkg . dependencies || { } ) ,
276- ...Object . keys ( pkg . peerDependencies || { } ) ,
277- // for @vue /compiler-sfc / server-renderer
278- ...[ 'path' , 'url' , 'stream' ] ,
279- // somehow these throw warnings for runtime-* package builds
280- ...treeShakenDeps ,
281- ]
282- }
228+ // Use shared function for external resolution
229+ return resolveExternalShared ( {
230+ pkg,
231+ format,
232+ target : process . env . TARGET ,
233+ isGlobalBuild,
234+ isBrowserESMBuild,
235+ isCompatPackage,
236+ packageOptions,
237+ } )
283238 }
284239
285240 function resolveNodePlugins ( ) {
286- // we are bundling forked consolidate.js in compiler-sfc which dynamically
287- // requires a ton of template engines which should be ignored.
288- /** @type {ReadonlyArray<string> } */
289- let cjsIgnores = [ ]
290- if ( pkg . name === '@vue/compiler-sfc' ) {
291- cjsIgnores = [
292- ...Object . keys ( consolidatePkg . devDependencies ) ,
293- 'vm' ,
294- 'crypto' ,
295- 'react-dom/server' ,
296- 'teacup/lib/express' ,
297- 'arc-templates/dist/es5' ,
298- 'then-pug' ,
299- 'then-jade' ,
300- ]
301- }
241+ // Use shared function for CJS ignores
242+ const cjsIgnores = resolveCJSIgnores ( process . env . TARGET )
302243
303244 const nodePlugins =
304245 ( format === 'cjs' && Object . keys ( pkg . devDependencies || { } ) . length ) ||
0 commit comments