SSR Loadable can not detect code splitting with typescript, ts-loader
See original GitHub issue💬 Questions and Help
Problem
typescript project like App.jsx can not code split with @loadable/babel-plugin.
To Reproduce
I’m forked this project and copied examples/server-side-rendering-ts
.
Example js code was transformed to ts or tsx.
After yarn build:webpack
, there is only one js file main.js in public/dist/node
and public/dist/web
. It seems like @loadable/component
not working properly.
If yarn start
, you can see an error “Invariant Violation: loadable: SSR requires @loadable/babel-plugin
, please install it”
Expected behavior
Output of yarn build:webpack
is letters-A.js
, letters-B.js
, letters-C.js
… etc and main.js
like server-side-rendering
.
Details
For typescript project, I changed some config
- Added ts-loader in webpack
- Transformed .js to .ts, .tsx (except minor issue about preventing uglify remove)
- Changed babel target from
src
tots-output
because babel can not read typescript directly.ts-output
is compiled files fromsrc
.
I guess my problem is ‘Loadable detection’.
Seeing ts-output/client/App.js
in here
(https://github.com/DylanJu/loadable-components/tree/master/examples/server-side-rendering-ts/ts-output/client)
App.tsx
const A = loadable(() => import('./letters/A'))
compiled App.js
const A = component_1.default(() => Promise.resolve().then(() => __importStar(require('./letters/A'))));
It seems keyword loadable
is gone. So @ladable/babel-plugin
can not detect code splitting. It’s just my opinion.
Please help me!
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (1 by maintainers)
Top GitHub Comments
Never mind. The order of loaders are important. I changed the loaders to
and it works perfectly now!
@neoziro @theKashey
It is solved by myself. The problem is because typescript compile as I guessed. Using webpack, babel and typescript same time,
A.tsx
is compiled in orderts-loader
,babel-loader
,webpack
. In my case, ts-loader changedloadable
based on typescript config.If configure tsconfig.json like this
It change App.tsx
const A = loadable(() => import('./letters/A'))
to
const A = component_1.default(() => Promise.resolve().then(() => __importStar(require('./letters/A'))));
Then
@loadable/babel-plugin
can’t detectloadable
My Solution
tsconfig.json
It don’t change
loadable(() => import('something')
so the detection is enable compile normally. I wish help someone like me. And I think it’s needed a guide to this for someone who use typescript.