Appearance
条目代码块
¥Entry Chunk
创建一个入口块,因为我们需要输出一个 JavaScript 文件:
¥An entry chunk is created, because we need to output a JavaScript file for:
导出入口模块的导出
¥Exporting the exports of the entry module
表示相应 entry 的执行点。
¥Representing the executing point of the corresponding entry.
存储入口模块及其依赖的代码(如果没有将代码拆分成单独的块)
¥Storing the code of the entry module and its dependencies (if not code-split into separate chunks)
假设你有一个可以单独运行的应用,但也可以作为库被其他应用使用。
¥Let's say you have an app that could run separately but also could be used as a library by other apps.
文件结构:
¥File structure:
js
// component.js
export function component() {
return 'Hello World';
}
// render.js
export function render(component) {
console.log(component());
}
// app.js
import { component } from './component.js';
import { render } from './render.js';
render(component);
// lib.js
export { component } from './component.js';配置:
¥Config:
js
export default defineConfig({
input: {
app: './app.js',
lib: './lib.js',
},
});Rolldown 将创建如下输出:
¥Rolldown will create outputs like:
js
import { component } from './common.js';
function render(component) {
console.log(component());
}
render(component);js
export { component } from './common.js';js
export function component() {
return 'Hello World';
}创建
lib.js是因为我们需要创建导出签名export { component }并将其导出到lib.js中。¥
lib.jsis created because we need to create the export signatureexport { component }and export it inlib.js.对于
app.js,虽然它不导出任何内容,但我们仍然需要创建app.js作为应用的执行点。¥For
app.js, though it doesn't export anything, we still need to createapp.jsas the executing point of the app.你还会注意到,从执行点
app.js开始,只有导入的模块(例如render.js)才会被执行。这是作为执行点的另一个原因和保证。¥You'll also notice, from the executing point
app.js, only modules, likerender.js, imported are executed. This is another reason and promise made by being the executing point.