Skip to content

Commit 308e09d

Browse files
committed
removed @loadable/babel-plugin, see notes.
1 parent 491b977 commit 308e09d

File tree

5 files changed

+55
-13
lines changed

5 files changed

+55
-13
lines changed

docs/backlog.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ There is a huge overlap between Babel and Webpack in terms of intent.
5454
If babel is for transpiling and webpack is for bundling, what's up
5555
with 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')
141154
const 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
149166
stats 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+
```

packages/incept/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"@dr.pogodin/babel-plugin-css-modules-transform": "1.10.0",
3535
"@inceptjs/framework": "^0.0.19",
3636
"@inceptjs/virtualfs": "^0.0.19",
37-
"@loadable/babel-plugin": "5.13.2",
3837
"@loadable/component": "5.15.0",
3938
"@loadable/server": "5.15.1",
4039
"@loadable/webpack-plugin": "5.15.1",

packages/incept/src/babel/defaults.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ export default {
1313
'@babel/plugin-transform-runtime',
1414
//adds react import where jsx is found
1515
'react-require',
16-
//allows to use import as a function
17-
'@loadable/babel-plugin',
1816
//import css server side
1917
[
2018
'@dr.pogodin/css-modules-transform', {

packages/incept/src/react/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path';
2-
import React, { ComponentType } from 'react'
3-
import ReactDOMServer from 'react-dom/server'
4-
import { ChunkExtractor, ChunkExtractorOptions } from '@loadable/server'
2+
import React, { ComponentType } from 'react';
3+
import ReactDOMServer from 'react-dom/server';
4+
import { ChunkExtractor, ChunkExtractorOptions } from '@loadable/server';
55
import { StaticRouter, matchPath } from 'react-router';
66
import { Request, Response } from '@inceptjs/framework';
77

@@ -254,9 +254,12 @@ export default class WithReact {
254254
route(
255255
path: string,
256256
file: string,
257-
layoutName: string = 'default'
257+
layout: string = 'default'
258258
): WithReact {
259-
this._routes[path] = { path, view: file, layout: layoutName }
259+
const resolved = this._application.withVirtualFS.resolvePath(file);
260+
Exception.require(!!resolved, 'Module not found %s', file);
261+
const view = resolved as string;
262+
this._routes[path] = { path, view, layout }
260263
return this
261264
}
262265

packages/incept/src/webpack/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export default class WithWebpack {
8484
'loadable-in-memory',
8585
'afterCompile',
8686
(compilation: Compilation) => {
87-
const loadable = new LoadablePlugin
87+
const loadable = new LoadablePlugin;
8888
if (!vfs.existsSync(buildPath)) {
8989
vfs.mkdirSync(buildPath, { recursive: true });
9090
}

0 commit comments

Comments
 (0)