MCPcopy
hub / github.com/vuejs/core / createConfig

Function createConfig

rollup.config.js:125–353  ·  view source on GitHub ↗

* * @param {PackageFormat} format * @param {OutputOptions} output * @param {ReadonlyArray<import('rollup').Plugin>} plugins * @returns {import('rollup').RollupOptions}

(format, output, plugins = [])

Source from the content-addressed store, hash-verified

123 * @returns {import('rollup').RollupOptions}
124 */
125function createConfig(format, output, plugins = []) {
126 if (!output) {
127 console.log(pico.yellow(`invalid format: "${format}"`))
128 process.exit(1)
129 }
130
131 const isProductionBuild =
132 process.env.__DEV__ === 'false' || /\.prod\.js$/.test(output.file)
133 const isBundlerESMBuild = /esm-bundler/.test(format)
134 const isBrowserESMBuild = /esm-browser/.test(format)
135 const isServerRenderer = name === 'server-renderer'
136 const isCJSBuild = format === 'cjs'
137 const isGlobalBuild = /global/.test(format)
138 const isCompatPackage = pkg.name === '@vue/compat'
139 const isCompatBuild = !!packageOptions.compat
140 const isBrowserBuild =
141 (isGlobalBuild || isBrowserESMBuild || isBundlerESMBuild) &&
142 !packageOptions.enableNonBrowserBranches
143
144 output.banner = banner
145
146 output.exports = isCompatPackage ? 'auto' : 'named'
147 if (isCJSBuild) {
148 output.esModule = true
149 }
150 output.sourcemap = !!process.env.SOURCE_MAP
151 output.externalLiveBindings = false
152 // https://github.com/rollup/rollup/pull/5380
153 output.reexportProtoFromExternal = false
154
155 if (isGlobalBuild) {
156 output.name = packageOptions.name
157 }
158
159 let entryFile = /runtime$/.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 = /runtime$/.test(format)
166 ? `src/esm-runtime.ts`
167 : `src/esm-index.ts`
168 }
169
170 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)?

Callers 3

rollup.config.jsFile · 0.85
createProductionConfigFunction · 0.85
createMinifiedConfigFunction · 0.85

Calls 8

resolveExternalFunction · 0.85
resolveReplaceFunction · 0.85
resolveDefineFunction · 0.85
resolveNodePluginsFunction · 0.85
testMethod · 0.80
resolveFunction · 0.70
resolveMethod · 0.65
warnFunction · 0.50

Tested by

no test coverage detected