zjffun blog

rollup external change execute order

更新于 写于 前端

Source code: polyfill.js → external → main.js

js
// main.js
import "./polyfill.js";
import "external";
console.log("main");

// polyfill.js
console.log("polyfill");

Bundle code: external → polyfill.js → main.js

js
import "external";
console.log("polyfill");
console.log("main");

Solution:

If polyfill.js ends up in a different chunk than main.js, correct execution order will be preserved. Example: not chunk -> chunk

See: