@wrdagency/react-islands 1.0.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -3
- package/dist/index.d.ts +46 -6
- package/dist/index.js +96 -136
- package/package.json +37 -15
- package/src/bin/commands/build.ts +73 -0
- package/src/bin/index.ts +7 -0
- package/src/bin/rollup/console.ts +23 -0
- package/src/bin/rollup/generation.ts +57 -0
- package/src/bin/rollup/index.ts +178 -0
- package/src/bin/rollup/options.ts +74 -0
- package/src/bin/rollup/plugins/runScriptAfterBuildPlugin.ts +43 -0
- package/src/bin/rollup/plugins/virtualizeDependencyPlugin.ts +34 -0
- package/src/bin/util/command.ts +101 -0
- package/src/index.tsx +5 -0
- package/src/island.tsx +94 -0
- package/src/util.tsx +41 -0
- package/dist/index.d.mts +0 -9
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -116
- package/dist/index.mjs.map +0 -1
- package/src/index.ts +0 -113
- package/tsconfig.json +0 -13
- package/tsup.config.ts +0 -10
package/dist/index.mjs
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined")
|
|
5
|
-
return require.apply(this, arguments);
|
|
6
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
8
|
-
var __async = (__this, __arguments, generator) => {
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
var fulfilled = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.next(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var rejected = (value) => {
|
|
18
|
-
try {
|
|
19
|
-
step(generator.throw(value));
|
|
20
|
-
} catch (e) {
|
|
21
|
-
reject(e);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
25
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// src/index.ts
|
|
30
|
-
import {
|
|
31
|
-
webpack
|
|
32
|
-
} from "webpack";
|
|
33
|
-
import tmp from "tmp";
|
|
34
|
-
import { renderToStaticMarkup } from "react-dom/server";
|
|
35
|
-
import { hydrateRoot } from "react-dom/client";
|
|
36
|
-
tmp.setGracefulCleanup();
|
|
37
|
-
var ReactIslandsWebpackPlugin = class _ReactIslandsWebpackPlugin {
|
|
38
|
-
createSubCompiler(dir, entry, options) {
|
|
39
|
-
const plugins = options.plugins.filter(
|
|
40
|
-
(plugin) => !(plugin instanceof _ReactIslandsWebpackPlugin)
|
|
41
|
-
);
|
|
42
|
-
const compilerOptions = {
|
|
43
|
-
mode: "development",
|
|
44
|
-
target: "node",
|
|
45
|
-
context: process.cwd(),
|
|
46
|
-
entry,
|
|
47
|
-
output: {
|
|
48
|
-
libraryTarget: "commonjs",
|
|
49
|
-
path: dir,
|
|
50
|
-
filename: "[name].js"
|
|
51
|
-
},
|
|
52
|
-
module: options.module,
|
|
53
|
-
stats: false,
|
|
54
|
-
devtool: false,
|
|
55
|
-
optimization: {
|
|
56
|
-
minimize: false
|
|
57
|
-
},
|
|
58
|
-
plugins
|
|
59
|
-
};
|
|
60
|
-
return webpack(compilerOptions);
|
|
61
|
-
}
|
|
62
|
-
apply(compiler) {
|
|
63
|
-
return __async(this, null, function* () {
|
|
64
|
-
let components = [];
|
|
65
|
-
const options = compiler.options;
|
|
66
|
-
const entry = typeof options.entry === "function" ? yield options.entry() : options.entry;
|
|
67
|
-
const { name: dir } = tmp.dirSync();
|
|
68
|
-
const { RawSource } = compiler.webpack.sources;
|
|
69
|
-
compiler.hooks.run.tapAsync(
|
|
70
|
-
"ReactIslandsWebpackPlugin",
|
|
71
|
-
(compiler2, callback) => {
|
|
72
|
-
components = Object.keys(entry);
|
|
73
|
-
const subCompiler = this.createSubCompiler(dir, entry, options);
|
|
74
|
-
subCompiler.run((err, stats) => {
|
|
75
|
-
if (err) {
|
|
76
|
-
console.error(err);
|
|
77
|
-
throw new Error("ReactIslandsWebpackPlugin: Error during compile.");
|
|
78
|
-
}
|
|
79
|
-
if (stats == null ? void 0 : stats.hasErrors()) {
|
|
80
|
-
console.log(stats == null ? void 0 : stats.toString());
|
|
81
|
-
throw new Error("ReactIslandsWebpackPlugin: Failed to compile.");
|
|
82
|
-
}
|
|
83
|
-
callback();
|
|
84
|
-
console.log("ReactIslandsWebpackPlugin: Compilation complete.");
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
);
|
|
88
|
-
compiler.hooks.thisCompilation.tap(
|
|
89
|
-
"ReactIslandsWebpackPlugin",
|
|
90
|
-
(compilation) => {
|
|
91
|
-
for (const name of components) {
|
|
92
|
-
const file = `${dir}/${name}.js`;
|
|
93
|
-
const { default: component } = __require(file);
|
|
94
|
-
const markup = renderToStaticMarkup(component());
|
|
95
|
-
compilation.emitAsset(`${name}.html`, new RawSource(markup));
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
);
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
function createIsland(name, Component) {
|
|
103
|
-
const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
104
|
-
if (isBrowser) {
|
|
105
|
-
document.querySelectorAll(`[data-react-component="${name}"]`).forEach((element) => {
|
|
106
|
-
const propsJSON = element.getAttribute("data-react-props") || "{}";
|
|
107
|
-
const props = JSON.parse(propsJSON);
|
|
108
|
-
hydrateRoot(element, Component(props));
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
export {
|
|
113
|
-
ReactIslandsWebpackPlugin,
|
|
114
|
-
createIsland
|
|
115
|
-
};
|
|
116
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import {\n\tCompilation,\n\tCompiler,\n\tConfiguration,\n\tWebpackOptionsNormalized,\n\twebpack,\n} from \"webpack\";\nimport tmp from \"tmp\";\nimport { renderToStaticMarkup } from \"react-dom/server\";\nimport { hydrateRoot } from \"react-dom/client\";\n\ntmp.setGracefulCleanup();\n\nexport class ReactIslandsWebpackPlugin {\n\tcreateSubCompiler(\n\t\tdir: string,\n\t\tentry: Record<string, any>,\n\t\toptions: WebpackOptionsNormalized\n\t): Compiler {\n\t\tconst plugins = options.plugins.filter(\n\t\t\t(plugin) => !(plugin instanceof ReactIslandsWebpackPlugin)\n\t\t);\n\n\t\tconst compilerOptions: Configuration = {\n\t\t\tmode: \"development\",\n\t\t\ttarget: \"node\",\n\t\t\tcontext: process.cwd(),\n\t\t\tentry,\n\t\t\toutput: {\n\t\t\t\tlibraryTarget: \"commonjs\",\n\t\t\t\tpath: dir,\n\t\t\t\tfilename: \"[name].js\",\n\t\t\t},\n\t\t\tmodule: options.module,\n\t\t\tstats: false,\n\t\t\tdevtool: false,\n\t\t\toptimization: {\n\t\t\t\tminimize: false,\n\t\t\t},\n\t\t\tplugins,\n\t\t};\n\n\t\treturn webpack(compilerOptions);\n\t}\n\n\tasync apply(compiler: Compiler) {\n\t\tlet components: string[] = [];\n\n\t\tconst options = compiler.options;\n\n\t\tconst entry =\n\t\t\ttypeof options.entry === \"function\"\n\t\t\t\t? await options.entry()\n\t\t\t\t: options.entry;\n\n\t\tconst { name: dir } = tmp.dirSync();\n\n\t\tconst { RawSource } = compiler.webpack.sources;\n\n\t\tcompiler.hooks.run.tapAsync(\n\t\t\t\"ReactIslandsWebpackPlugin\",\n\t\t\t(compiler: Compiler, callback) => {\n\t\t\t\tcomponents = Object.keys(entry);\n\n\t\t\t\tconst subCompiler = this.createSubCompiler(dir, entry, options);\n\n\t\t\t\tsubCompiler.run((err, stats) => {\n\t\t\t\t\tif (err) {\n\t\t\t\t\t\tconsole.error(err);\n\t\t\t\t\t\tthrow new Error(\"ReactIslandsWebpackPlugin: Error during compile.\");\n\t\t\t\t\t}\n\n\t\t\t\t\tif (stats?.hasErrors()) {\n\t\t\t\t\t\tconsole.log(stats?.toString());\n\t\t\t\t\t\tthrow new Error(\"ReactIslandsWebpackPlugin: Failed to compile.\");\n\t\t\t\t\t}\n\n\t\t\t\t\tcallback();\n\t\t\t\t\tconsole.log(\"ReactIslandsWebpackPlugin: Compilation complete.\");\n\t\t\t\t});\n\t\t\t}\n\t\t);\n\n\t\tcompiler.hooks.thisCompilation.tap(\n\t\t\t\"ReactIslandsWebpackPlugin\",\n\t\t\t(compilation: Compilation) => {\n\t\t\t\tfor (const name of components) {\n\t\t\t\t\tconst file = `${dir}/${name}.js`;\n\t\t\t\t\tconst { default: component } = require(file);\n\n\t\t\t\t\tconst markup = renderToStaticMarkup(component());\n\n\t\t\t\t\tcompilation.emitAsset(`${name}.html`, new RawSource(markup));\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n}\n\nexport function createIsland(name: string, Component: React.FC) {\n\tconst isBrowser =\n\t\ttypeof window !== \"undefined\" && typeof window.document !== \"undefined\";\n\n\tif (isBrowser) {\n\t\tdocument\n\t\t\t.querySelectorAll(`[data-react-component=\"${name}\"]`)\n\t\t\t.forEach((element) => {\n\t\t\t\tconst propsJSON = element.getAttribute(\"data-react-props\") || \"{}\";\n\t\t\t\tconst props = JSON.parse(propsJSON);\n\t\t\t\thydrateRoot(element, Component(props));\n\t\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EAKC;AAAA,OACM;AACP,OAAO,SAAS;AAChB,SAAS,4BAA4B;AACrC,SAAS,mBAAmB;AAE5B,IAAI,mBAAmB;AAEhB,IAAM,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AA,QAC9B;AAAA,QACA,CAAC,gBAA6B;AAC7B,qBAAW,QAAQ,YAAY;AAC9B,kBAAM,OAAO,GAAG,GAAG,IAAI,IAAI;AAC3B,kBAAM,EAAE,SAAS,UAAU,IAAI,UAAQ,IAAI;AAE3C,kBAAM,SAAS,qBAAqB,UAAU,CAAC;AAE/C,wBAAY,UAAU,GAAG,IAAI,SAAS,IAAI,UAAU,MAAM,CAAC;AAAA,UAC5D;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA;AACD;AAEO,SAAS,aAAa,MAAc,WAAqB;AAC/D,QAAM,YACL,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AAE7D,MAAI,WAAW;AACd,aACE,iBAAiB,0BAA0B,IAAI,IAAI,EACnD,QAAQ,CAAC,YAAY;AACrB,YAAM,YAAY,QAAQ,aAAa,kBAAkB,KAAK;AAC9D,YAAM,QAAQ,KAAK,MAAM,SAAS;AAClC,kBAAY,SAAS,UAAU,KAAK,CAAC;AAAA,IACtC,CAAC;AAAA,EACH;AACD;","names":["compiler"]}
|
package/src/index.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Compilation,
|
|
3
|
-
Compiler,
|
|
4
|
-
Configuration,
|
|
5
|
-
WebpackOptionsNormalized,
|
|
6
|
-
webpack,
|
|
7
|
-
} from "webpack";
|
|
8
|
-
import tmp from "tmp";
|
|
9
|
-
import { renderToStaticMarkup } from "react-dom/server";
|
|
10
|
-
import { hydrateRoot } from "react-dom/client";
|
|
11
|
-
|
|
12
|
-
tmp.setGracefulCleanup();
|
|
13
|
-
|
|
14
|
-
export class ReactIslandsWebpackPlugin {
|
|
15
|
-
createSubCompiler(
|
|
16
|
-
dir: string,
|
|
17
|
-
entry: Record<string, any>,
|
|
18
|
-
options: WebpackOptionsNormalized
|
|
19
|
-
): Compiler {
|
|
20
|
-
const plugins = options.plugins.filter(
|
|
21
|
-
(plugin) => !(plugin instanceof ReactIslandsWebpackPlugin)
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
const compilerOptions: Configuration = {
|
|
25
|
-
mode: "development",
|
|
26
|
-
target: "node",
|
|
27
|
-
context: process.cwd(),
|
|
28
|
-
entry,
|
|
29
|
-
output: {
|
|
30
|
-
libraryTarget: "commonjs",
|
|
31
|
-
path: dir,
|
|
32
|
-
filename: "[name].js",
|
|
33
|
-
},
|
|
34
|
-
module: options.module,
|
|
35
|
-
stats: false,
|
|
36
|
-
devtool: false,
|
|
37
|
-
optimization: {
|
|
38
|
-
minimize: false,
|
|
39
|
-
},
|
|
40
|
-
plugins,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return webpack(compilerOptions);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async apply(compiler: Compiler) {
|
|
47
|
-
let components: string[] = [];
|
|
48
|
-
|
|
49
|
-
const options = compiler.options;
|
|
50
|
-
|
|
51
|
-
const entry =
|
|
52
|
-
typeof options.entry === "function"
|
|
53
|
-
? await options.entry()
|
|
54
|
-
: options.entry;
|
|
55
|
-
|
|
56
|
-
const { name: dir } = tmp.dirSync();
|
|
57
|
-
|
|
58
|
-
const { RawSource } = compiler.webpack.sources;
|
|
59
|
-
|
|
60
|
-
compiler.hooks.run.tapAsync(
|
|
61
|
-
"ReactIslandsWebpackPlugin",
|
|
62
|
-
(compiler: Compiler, callback) => {
|
|
63
|
-
components = Object.keys(entry);
|
|
64
|
-
|
|
65
|
-
const subCompiler = this.createSubCompiler(dir, entry, options);
|
|
66
|
-
|
|
67
|
-
subCompiler.run((err, stats) => {
|
|
68
|
-
if (err) {
|
|
69
|
-
console.error(err);
|
|
70
|
-
throw new Error("ReactIslandsWebpackPlugin: Error during compile.");
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (stats?.hasErrors()) {
|
|
74
|
-
console.log(stats?.toString());
|
|
75
|
-
throw new Error("ReactIslandsWebpackPlugin: Failed to compile.");
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
callback();
|
|
79
|
-
console.log("ReactIslandsWebpackPlugin: Compilation complete.");
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
compiler.hooks.thisCompilation.tap(
|
|
85
|
-
"ReactIslandsWebpackPlugin",
|
|
86
|
-
(compilation: Compilation) => {
|
|
87
|
-
for (const name of components) {
|
|
88
|
-
const file = `${dir}/${name}.js`;
|
|
89
|
-
const { default: component } = require(file);
|
|
90
|
-
|
|
91
|
-
const markup = renderToStaticMarkup(component());
|
|
92
|
-
|
|
93
|
-
compilation.emitAsset(`${name}.html`, new RawSource(markup));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function createIsland(name: string, Component: React.FC) {
|
|
101
|
-
const isBrowser =
|
|
102
|
-
typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
103
|
-
|
|
104
|
-
if (isBrowser) {
|
|
105
|
-
document
|
|
106
|
-
.querySelectorAll(`[data-react-component="${name}"]`)
|
|
107
|
-
.forEach((element) => {
|
|
108
|
-
const propsJSON = element.getAttribute("data-react-props") || "{}";
|
|
109
|
-
const props = JSON.parse(propsJSON);
|
|
110
|
-
hydrateRoot(element, Component(props));
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"outDir": "./dist/",
|
|
4
|
-
"target": "es2016",
|
|
5
|
-
"module": "Node16",
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"allowSyntheticDefaultImports": true,
|
|
8
|
-
"forceConsistentCasingInFileNames": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"skipLibCheck": true
|
|
11
|
-
},
|
|
12
|
-
"exclude": ["dist", "node_modules"]
|
|
13
|
-
}
|