Last active
July 28, 2020 13:13
-
-
Save surma/519428064297de8a32639d1ec1acc720 to your computer and use it in GitHub Desktop.
Rollup prunes dynamic import hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
build | |
node_modules | |
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("lol"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import("./dynamic.js"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "rollup-purge", | |
"scripts": { | |
"build": "rollup -c" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MARKER = "myimport:"; | |
export default { | |
input: "input.js", | |
output: { | |
dir: "build", | |
format: "esm" | |
}, | |
preserveEntrySignatures: false, | |
plugins: [ | |
{ | |
resolveId(id) { | |
if (id === MARKER) { | |
return MARKER; | |
} | |
}, | |
load(id) { | |
if (id === MARKER) { | |
return `export function myimport(id){}`; | |
} | |
}, | |
transform(code, id) { | |
if (id === MARKER) { | |
return; | |
} | |
return ` | |
import {myimport} from "${MARKER}"; ${code} | |
// It works with the following line | |
// self[Symbol()] = myimport; | |
`; | |
}, | |
renderDynamicImport(moduleId) { | |
if (moduleId === MARKER) { | |
return; | |
} | |
return { | |
left: "myimport(", | |
right: ", import.meta.url)" | |
}; | |
} | |
} | |
] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment