Do imports used in getStaticProps get bundled? #18051
-
I want to make sure my getStaticProps code does not end up in JS bundles, and that includes functions called which have to be imported at the page level. Does using Typescript have any effect? Do I need to use require() and/or node’s fs.readfileSync to load modules and any API keys inside the gSP function body? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Using typescript has no effect on this and as the docs mention, node code/code included in getStaticProps/getServerSideProps/getStaticPaths does not get bundled client side. You can easily confirm this e.g. if you enable |
Beta Was this translation helpful? Give feedback.
-
https://next-code-elimination.now.sh/s/yDIpMw_Iw looks like I just need to be careful to avoid combining client and server API exports in the same module(s). |
Beta Was this translation helpful? Give feedback.
Using typescript has no effect on this and as the docs mention, node code/code included in getStaticProps/getServerSideProps/getStaticPaths does not get bundled client side. You can easily confirm this e.g. if you enable
browserSourceMaps: true
in next.config.js > experimental and check the resulting source maps, which show any server side code greyed out.