@@ -54,6 +54,19 @@ There is a huge overlap between Babel and Webpack in terms of intent.
5454If babel is for transpiling and webpack is for bundling, what's up
5555with isomorphic plugins?
5656
57+ ** @loadable/babel-plugin **
58+
59+ This is not what everyone thinks. This plugin requires that you bundle
60+ your server files as well as your client similar to their
61+ [ github] ( https://github.com/gregberge/loadable-components/tree/main/examples/server-side-rendering )
62+ example, otherwise will not work at all. Additionally I thought at
63+ first that ` @loadable ` was this magical sword that magically transpiles
64+ CSS and the like, but again would only work if you use ` webpack ` to
65+ bundle your server code.
66+
67+ > This item is marked as passive, because it was the ` @loadable `
68+ author's intent to do it that way.
69+
5770## Active
5871
5972** This browser doesn't support requestAnimationFrame. Make sure that you load a polyfill in older browsers. https://reactjs.org/link/react-polyfills **
@@ -141,10 +154,39 @@ const statsFile = path.resolve('../dist/loadable-stats.json')
141154const chunkExtractor = new ChunkExtractor ({ statsFile })
142155```
143156
144- Implementing loadable in general with chunking based on their docs,
145- though works, is quite clunky and loadable puts some branding in the
146- HTML.
157+ The problem with the code above, is that it requires you write your
158+ build files to actual files which counters the point of ` webpack `
159+ allowing ` writeToDisk: false ` . Additional tooling is required to get
160+ this working and the
161+ [ docs] ( https://loadable-components.com/docs/server-side-rendering/ ) is
162+ no where near their example in
163+ [ github] ( https://github.com/gregberge/loadable-components/tree/main/examples/server-side-rendering )
147164
148165** UPDATE: 0.0.16** What I did was add a webpack hook to compile the
149166stats again and save it in VirtualFS then retrieved those contents when
150- rendering.
167+ rendering.
168+
169+ ``` js
170+ const vfs = require (' @inceptjs/virtualfs' )
171+ const buildURL = ' /.build'
172+ const buildPath = path .join (process .cwd (), ' .build' )
173+ const compiler = webpack ({ ... })
174+ compiler .hooks .afterCompile .tap (' loadable-in-memory' , (compilation : Compilation ) => {
175+ const loadable = new LoadablePlugin
176+ if (! vfs .existsSync (buildPath)) {
177+ vfs .mkdirSync (buildPath, { recursive: true })
178+ }
179+ vfs .writeFileSync (
180+ path .join (buildPath, ' stats.json' ),
181+ // @ts-ignore `handleEmit()` already stringifies the object
182+ loadable .handleEmit (compilation).source ()
183+ )
184+ })
185+
186+ ...
187+
188+ const extractor = new ChunkExtractor ({
189+ statsFile: path .join (buildPath, ' static/stats.json' ),
190+ publicPath: buildURL
191+ })
192+ ```
0 commit comments