rolldownCjsExternalPlugin() — vite Function Reference
Architecture documentation for the rolldownCjsExternalPlugin() function in rolldownDepPlugin.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD ac03445a_81e1_acd2_c81d_996b0b9b2a16["rolldownCjsExternalPlugin()"] 88c474dd_3ef0_0479_2549_43cd02a6f84b["rolldownDepPlugin.ts"] ac03445a_81e1_acd2_c81d_996b0b9b2a16 -->|defined in| 88c474dd_3ef0_0479_2549_43cd02a6f84b 27cb44a2_ca79_d2a4_e536_a5e4bc22ffbf["prepareRolldownOptimizerRun()"] 27cb44a2_ca79_d2a4_e536_a5e4bc22ffbf -->|calls| ac03445a_81e1_acd2_c81d_996b0b9b2a16 fb27ca2e_1576_f57b_b1dd_9bac4dddcf04["isNodeBuiltin()"] ac03445a_81e1_acd2_c81d_996b0b9b2a16 -->|calls| fb27ca2e_1576_f57b_b1dd_9bac4dddcf04 style ac03445a_81e1_acd2_c81d_996b0b9b2a16 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/node/optimizer/rolldownDepPlugin.ts lines 369–424
export function rolldownCjsExternalPlugin(
externals: string[],
platform: 'node' | 'browser' | 'neutral',
): Plugin | undefined {
// Skip this plugin for `platform: 'node'` as `require` is available in Node
// and that is more accurate than converting to `import`
if (platform === 'node') {
return undefined
}
// Skip this plugin for `platform: 'neutral'` as we are not sure whether `require` is available
if (platform === 'neutral') {
return undefined
}
// Apply this plugin for `platform: 'browser'` as `require` is not available in browser and
// converting to `import` would be necessary to make the code work
platform satisfies 'browser'
const filter = new RegExp(externals.map(matchesEntireLine).join('|'))
return {
name: 'cjs-external',
resolveId: {
filter: { id: [prefixRegex(nonFacadePrefix), filter] },
handler(id, _importer, options) {
if (id.startsWith(nonFacadePrefix)) {
return {
id: id.slice(nonFacadePrefix.length),
external: 'absolute',
}
}
if (options.kind === 'require-call') {
return {
id: cjsExternalFacadeNamespace + id,
}
}
return {
id,
external: 'absolute',
}
},
},
load: {
filter: { id: prefixRegex(cjsExternalFacadeNamespace) },
handler(id) {
const idWithoutNamespace = id.slice(cjsExternalFacadeNamespace.length)
return {
code: `\
import * as m from ${JSON.stringify(nonFacadePrefix + idWithoutNamespace)};
module.exports = ${isNodeBuiltin(idWithoutNamespace) ? 'm.default' : '{ ...m }'};
`,
}
},
},
}
}
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does rolldownCjsExternalPlugin() do?
rolldownCjsExternalPlugin() is a function in the vite codebase, defined in packages/vite/src/node/optimizer/rolldownDepPlugin.ts.
Where is rolldownCjsExternalPlugin() defined?
rolldownCjsExternalPlugin() is defined in packages/vite/src/node/optimizer/rolldownDepPlugin.ts at line 369.
What does rolldownCjsExternalPlugin() call?
rolldownCjsExternalPlugin() calls 1 function(s): isNodeBuiltin.
What calls rolldownCjsExternalPlugin()?
rolldownCjsExternalPlugin() is called by 1 function(s): prepareRolldownOptimizerRun.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free