parcel: Code splitting is not working
π bug report
Code splitting
{
"presets": [
"env",
"stage-2"
],
"plugins": [
"transform-runtime",
"dynamic-import-node"
]
}
π€ Expected Behavior
The build should contain one javascript file per page since I import them asynchronously.
π― Current Behavior
Thereβs only one javascript file.
π¦ Context
I have a Vue application with webpack and Iβm trying to migrate to parcel. My application has 5 pages that are lazy-loaded with const TheHome = () => import('../components/TheHome').
π» Code Sample
I made an example that reproduce my problem. To try you can execute yarn dev or yarn build.
https://github.com/maxirozay/test-parcel
π Your Environment
| Software | Version(s) |
|---|---|
| Parcel | 1.6.2 |
| Node | 8.9.4 |
| npm/Yarn | 1.3.2 |
| Operating System | linux (Solus) |
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 11
- Comments: 19 (1 by maintainers)
Commits related to this issue
- investigating code splitting issues - likely a known bug. https://github.com/parcel-bundler/parcel/issues/905 — committed to glomotion/glo-2 by glomotion 6 years ago
Closing. I believe this is because you have
dynamic-import-nodein your babelrc. This means babel will compile away theimport()syntax before parcel sees it, and therefore no code splitting occurs. That babel plugin just compilesimport()torequire()which means it will be in a single bundle.@jeanfortheweb with your branch I get the error
The file
prelude.min.jsdoesnβt exist butprelude.jsdoes exist.If I remove the code that use
prelude.min.jsit works but still no code splitting. I have one file forjs,css,htmland an emptymapfile.@davibe check this issue , https://github.com/parcel-bundler/parcel/issues/1547
@neculaesei I tried to update parcel to 1.9.7 and parcel-bundler to 1.9.7 and use your babelrc config and I get the error
Cannot read property 'add' of undefined at JSPackager.addAsset...JSPackager.js:57:32.Iβm also running into this issue.