I have developed a web application that consists of multiple pages along with some JavaScript files containing shared code.
- common1.js
- common2.js
- page1.js
- page2.js
- page3.js
...
The shared files are being loaded with page1 and, upon a button click, the page transitions to either page2 or page3. I utilize Closure Compiler and treat each page as a chunk.
--js "../common1.js" \
--chunk common1.min:1 \
--js "../common2.js" \
--chunk common2.min:1:common1.min \
--js "../page1.js" \
--chunk page1.min:1:common2.min \
--js "../page2.js" \
--chunk page2.min:1:common2.min \
Everything is functioning as intended and all the chunks are being loaded properly. (ADVANCED_OPTIMIZATIONS)
However, I am faced with the need to incorporate modules. I have refactored the JavaScript files to use import/export statements. The issue arises when all the code gets moved to my entry point, leaving the other chunks empty.
--compilation_level ADVANCED_OPTIMIZATIONS \
--language_out ECMASCRIPT_2021 \
--dynamic_import_alias "dynamicImport" \
--chunk_output_type "ES_MODULES" \
--dependency_mode PRUNE_LEGACY \
--entry_point "${JS_PATH}/page1.js" \
For example, page2 and page3 end up empty.
What am I missing here? The only workaround I have come across is to build each page individually. However, this would lead to larger file outputs since the shared code cannot be utilized. (It is cached, so there is no additional load time)