@unpackjs/plugin-react 2.1.0 → 2.1.1
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/dist/index.cjs +183 -76
- package/dist/index.js +157 -35
- package/dist/injectScript.js +82 -0
- package/dist/{react-compiler-loader/index.js → reactCompilerLoader.mjs} +11 -14
- package/{dist → dist-types}/index.d.ts.map +1 -1
- package/{dist → dist-types}/mpa.d.ts.map +1 -1
- package/{dist/react-compiler-loader/index.d.ts → dist-types/reactCompilerLoader.d.ts} +1 -1
- package/dist-types/reactCompilerLoader.d.ts.map +1 -0
- package/package.json +10 -9
- package/dist/click-to-component/index.cjs +0 -110
- package/dist/click-to-component/index.js +0 -68
- package/dist/click-to-component/injectScript.js +0 -116
- package/dist/mpa.cjs +0 -152
- package/dist/mpa.js +0 -109
- package/dist/react-compiler-loader/index.cjs +0 -95
- package/dist/react-compiler-loader/index.d.ts.map +0 -1
- package/dist/splitChunks.cjs +0 -59
- package/dist/splitChunks.js +0 -27
- /package/{dist → dist-types}/click-to-component/index.d.ts +0 -0
- /package/{dist → dist-types}/click-to-component/index.d.ts.map +0 -0
- /package/{dist → dist-types}/index.d.ts +0 -0
- /package/{dist → dist-types}/mpa.d.ts +0 -0
- /package/{dist → dist-types}/splitChunks.d.ts +0 -0
- /package/{dist → dist-types}/splitChunks.d.ts.map +0 -0
package/dist/mpa.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import 'module';
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
3
|
-
import node_fs from "node:fs";
|
|
4
|
-
import node_path from "node:path";
|
|
5
|
-
import { TEMPLATE_CONTENT, TEMP_DIR, colors, getPathInJs, isDevServer, isFunction, isPlainObject, logger, removeDir } from "@unpackjs/core";
|
|
6
|
-
const applyMpaConfig = ({ config, unpackConfig, mergeConfig, HtmlPlugin })=>{
|
|
7
|
-
if (!unpackConfig.mpa) return config;
|
|
8
|
-
const isRspack = 'rspack' === unpackConfig.bundler;
|
|
9
|
-
const tempDirectory = node_path.join(TEMP_DIR, 'mpa');
|
|
10
|
-
const userOptions = isPlainObject(unpackConfig.mpa) ? unpackConfig.mpa : {};
|
|
11
|
-
const getPageConfig = (indexPath)=>{
|
|
12
|
-
const filePath = node_path.join(indexPath, '../config.json');
|
|
13
|
-
let pageConfig = {};
|
|
14
|
-
if (node_fs.existsSync(filePath)) pageConfig = JSON.parse(node_fs.readFileSync(filePath, 'utf-8'));
|
|
15
|
-
return pageConfig;
|
|
16
|
-
};
|
|
17
|
-
const createTempFile = (entry)=>{
|
|
18
|
-
var _userOptions_globalImport, _unpackConfig_html;
|
|
19
|
-
removeDir(node_path.join(unpackConfig.root, tempDirectory));
|
|
20
|
-
const globalImport = (null == (_userOptions_globalImport = userOptions.globalImport) ? void 0 : _userOptions_globalImport.reduce((acc, curr)=>`${acc}\nimport '${getPathInJs(node_path.resolve(unpackConfig.root, curr))}'`, '')) || '';
|
|
21
|
-
const { layout } = userOptions;
|
|
22
|
-
const layoutImport = layout ? `import Layout from '${getPathInJs(node_path.resolve(unpackConfig.root, layout))}'` : '';
|
|
23
|
-
const layoutJSX = layout ? '<Layout><App /></Layout>' : '<App />';
|
|
24
|
-
const rootElement = `document.getElementById('${null == (_unpackConfig_html = unpackConfig.html) ? void 0 : _unpackConfig_html.mountId}')`;
|
|
25
|
-
const reactDOMSource = 'react-dom/client';
|
|
26
|
-
const renderer = `ReactDOM.createRoot(${rootElement}).render(${layoutJSX})`;
|
|
27
|
-
Object.entries(entry).forEach(([entryName, entryConfig])=>{
|
|
28
|
-
const filePath = node_path.join(unpackConfig.root, tempDirectory, `${entryName}.jsx`);
|
|
29
|
-
const tpl = `
|
|
30
|
-
import React from 'react'
|
|
31
|
-
import ReactDOM from '${reactDOMSource}'
|
|
32
|
-
import App from '${getPathInJs(entryConfig.import[0])}'${layoutImport && `\n${layoutImport}`}
|
|
33
|
-
${globalImport}
|
|
34
|
-
${renderer}
|
|
35
|
-
`;
|
|
36
|
-
const dir = node_path.dirname(filePath);
|
|
37
|
-
if (!node_fs.existsSync(dir)) node_fs.mkdirSync(dir, {
|
|
38
|
-
recursive: true
|
|
39
|
-
});
|
|
40
|
-
node_fs.writeFileSync(filePath, tpl, 'utf-8');
|
|
41
|
-
entryConfig.import[0] = filePath;
|
|
42
|
-
});
|
|
43
|
-
return entry;
|
|
44
|
-
};
|
|
45
|
-
const collectEntry = ()=>{
|
|
46
|
-
const start = performance.now();
|
|
47
|
-
const entry = {};
|
|
48
|
-
const html = [];
|
|
49
|
-
const getIndexFilePath = (dir)=>{
|
|
50
|
-
const extensions = [
|
|
51
|
-
'.tsx',
|
|
52
|
-
'.jsx'
|
|
53
|
-
];
|
|
54
|
-
for (const extension of extensions){
|
|
55
|
-
const indexFilePath = node_path.join(dir, `index${extension}`);
|
|
56
|
-
if (node_fs.existsSync(indexFilePath)) return indexFilePath;
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
59
|
-
};
|
|
60
|
-
const pagesRoot = node_path.join(unpackConfig.root, 'src', 'pages');
|
|
61
|
-
node_fs.readdirSync(pagesRoot).forEach((filename)=>{
|
|
62
|
-
if (filename.startsWith('.')) return;
|
|
63
|
-
const indexFilePath = getIndexFilePath(node_path.join(pagesRoot, filename));
|
|
64
|
-
if (indexFilePath) {
|
|
65
|
-
var _unpackConfig_html, _unpackConfig_html1, _unpackConfig_html2, _unpackConfig_html3, _unpackConfig_html4, _unpackConfig_html5, _unpackConfig_html6, _unpackConfig_html7, _unpackConfig_html8;
|
|
66
|
-
const pageConfig = getPageConfig(indexFilePath);
|
|
67
|
-
let entryName = true === userOptions.lowerCase ? filename.toLowerCase() : filename;
|
|
68
|
-
if (pageConfig.filename) entryName = pageConfig.filename.slice(0, -5);
|
|
69
|
-
entry[entryName] = {
|
|
70
|
-
import: [
|
|
71
|
-
indexFilePath
|
|
72
|
-
]
|
|
73
|
-
};
|
|
74
|
-
if (pageConfig.template) pageConfig.template = node_path.join(indexFilePath, '../', pageConfig.template);
|
|
75
|
-
html.push({
|
|
76
|
-
template: (null == (_unpackConfig_html = unpackConfig.html) ? void 0 : _unpackConfig_html.template) || (isRspack ? void 0 : ''),
|
|
77
|
-
templateContent: (null == (_unpackConfig_html1 = unpackConfig.html) ? void 0 : _unpackConfig_html1.templateContent) || ((null == (_unpackConfig_html2 = unpackConfig.html) ? void 0 : _unpackConfig_html2.template) ? isRspack ? void 0 : false : TEMPLATE_CONTENT),
|
|
78
|
-
minify: false,
|
|
79
|
-
filename: `${entryName}.html`,
|
|
80
|
-
chunks: [
|
|
81
|
-
entryName
|
|
82
|
-
],
|
|
83
|
-
...pageConfig,
|
|
84
|
-
templateParameters: {
|
|
85
|
-
mountId: null == (_unpackConfig_html3 = unpackConfig.html) ? void 0 : _unpackConfig_html3.mountId,
|
|
86
|
-
title: isFunction(null == (_unpackConfig_html4 = unpackConfig.html) ? void 0 : _unpackConfig_html4.title) ? null == (_unpackConfig_html5 = unpackConfig.html) ? void 0 : _unpackConfig_html5.title({
|
|
87
|
-
entryName
|
|
88
|
-
}) : (null == (_unpackConfig_html6 = unpackConfig.html) ? void 0 : _unpackConfig_html6.title) || '',
|
|
89
|
-
headTag: (null == (_unpackConfig_html7 = unpackConfig.html) ? void 0 : _unpackConfig_html7.headTag) || '',
|
|
90
|
-
...null == (_unpackConfig_html8 = unpackConfig.html) ? void 0 : _unpackConfig_html8.templateParameters,
|
|
91
|
-
...pageConfig.templateParameters
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
isDevServer() || logger.info(`collect entries in ${(performance.now() - start).toFixed(2)}ms ${colors.dim('[MPA]')}`);
|
|
97
|
-
return {
|
|
98
|
-
entry,
|
|
99
|
-
html
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
const { entry, html } = collectEntry();
|
|
103
|
-
config = mergeConfig(config, {
|
|
104
|
-
entry: createTempFile(entry),
|
|
105
|
-
plugins: html.map((h)=>new HtmlPlugin(h))
|
|
106
|
-
});
|
|
107
|
-
return config;
|
|
108
|
-
};
|
|
109
|
-
export { applyMpaConfig };
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
|
-
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: definition[key]
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
})();
|
|
20
|
-
(()=>{
|
|
21
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
-
})();
|
|
23
|
-
(()=>{
|
|
24
|
-
__webpack_require__.r = (exports1)=>{
|
|
25
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
-
value: 'Module'
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
-
value: true
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
})();
|
|
33
|
-
var __webpack_exports__ = {};
|
|
34
|
-
__webpack_require__.r(__webpack_exports__);
|
|
35
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
-
default: ()=>reactCompilerLoader
|
|
37
|
-
});
|
|
38
|
-
const core_namespaceObject = require("@babel/core");
|
|
39
|
-
const plugin_proposal_decorators_namespaceObject = require("@babel/plugin-proposal-decorators");
|
|
40
|
-
var plugin_proposal_decorators_default = /*#__PURE__*/ __webpack_require__.n(plugin_proposal_decorators_namespaceObject);
|
|
41
|
-
const plugin_transform_class_properties_namespaceObject = require("@babel/plugin-transform-class-properties");
|
|
42
|
-
var plugin_transform_class_properties_default = /*#__PURE__*/ __webpack_require__.n(plugin_transform_class_properties_namespaceObject);
|
|
43
|
-
const external_babel_plugin_react_compiler_namespaceObject = require("babel-plugin-react-compiler");
|
|
44
|
-
var external_babel_plugin_react_compiler_default = /*#__PURE__*/ __webpack_require__.n(external_babel_plugin_react_compiler_namespaceObject);
|
|
45
|
-
const defaultBabelParsePlugins = [
|
|
46
|
-
'jsx',
|
|
47
|
-
"typescript"
|
|
48
|
-
];
|
|
49
|
-
async function reactCompilerLoader(input, _inputSourceMap) {
|
|
50
|
-
const callback = this.async();
|
|
51
|
-
try {
|
|
52
|
-
const options = this.getOptions();
|
|
53
|
-
const result = await core_namespaceObject.transformAsync(input, {
|
|
54
|
-
sourceFileName: this.resourcePath,
|
|
55
|
-
filename: this.resourcePath,
|
|
56
|
-
cloneInputAst: false,
|
|
57
|
-
plugins: [
|
|
58
|
-
[
|
|
59
|
-
external_babel_plugin_react_compiler_default(),
|
|
60
|
-
options
|
|
61
|
-
],
|
|
62
|
-
[
|
|
63
|
-
plugin_proposal_decorators_default(),
|
|
64
|
-
{
|
|
65
|
-
legacy: true
|
|
66
|
-
}
|
|
67
|
-
],
|
|
68
|
-
[
|
|
69
|
-
plugin_transform_class_properties_default()
|
|
70
|
-
]
|
|
71
|
-
],
|
|
72
|
-
parserOpts: {
|
|
73
|
-
plugins: [
|
|
74
|
-
...defaultBabelParsePlugins
|
|
75
|
-
]
|
|
76
|
-
},
|
|
77
|
-
ast: false,
|
|
78
|
-
sourceMaps: true,
|
|
79
|
-
configFile: false,
|
|
80
|
-
babelrc: false
|
|
81
|
-
});
|
|
82
|
-
if (!result) throw new TypeError('babel.transformAsync with react compiler plugin returns null');
|
|
83
|
-
const { code, map } = result;
|
|
84
|
-
callback(null, code ?? void 0, map ?? void 0);
|
|
85
|
-
} catch (e) {
|
|
86
|
-
callback(e);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
exports["default"] = __webpack_exports__["default"];
|
|
90
|
-
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
91
|
-
"default"
|
|
92
|
-
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
93
|
-
Object.defineProperty(exports, '__esModule', {
|
|
94
|
-
value: true
|
|
95
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react-compiler-loader/index.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,yBAAyB,GAAG;IACtC,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;CAC3B,CAAA;AAMD,wBAA8B,mBAAmB,CAAC,IAAI,KAAA,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,iBAiC1F"}
|
package/dist/splitChunks.cjs
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: definition[key]
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
})();
|
|
11
|
-
(()=>{
|
|
12
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
-
})();
|
|
14
|
-
(()=>{
|
|
15
|
-
__webpack_require__.r = (exports1)=>{
|
|
16
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
-
value: 'Module'
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
-
value: true
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
})();
|
|
24
|
-
var __webpack_exports__ = {};
|
|
25
|
-
__webpack_require__.r(__webpack_exports__);
|
|
26
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
applySplitChunksConfig: ()=>applySplitChunksConfig
|
|
28
|
-
});
|
|
29
|
-
const core_namespaceObject = require("@unpackjs/core");
|
|
30
|
-
const applySplitChunksConfig = ({ config, unpackConfig })=>{
|
|
31
|
-
if ('split-by-experience' !== unpackConfig.performance.chunkSplit.strategy) return config;
|
|
32
|
-
const currentConfig = config.optimization.splitChunks;
|
|
33
|
-
const extraGroups = {};
|
|
34
|
-
extraGroups.react = {
|
|
35
|
-
name: 'lib-react',
|
|
36
|
-
test: (0, core_namespaceObject.isDevServer)() ? /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/,
|
|
37
|
-
priority: 0
|
|
38
|
-
};
|
|
39
|
-
extraGroups.router = {
|
|
40
|
-
name: 'lib-router',
|
|
41
|
-
test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
|
|
42
|
-
priority: 0
|
|
43
|
-
};
|
|
44
|
-
config.optimization.splitChunks = {
|
|
45
|
-
...currentConfig,
|
|
46
|
-
cacheGroups: {
|
|
47
|
-
...extraGroups,
|
|
48
|
-
...currentConfig.cacheGroups
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
return config;
|
|
52
|
-
};
|
|
53
|
-
exports.applySplitChunksConfig = __webpack_exports__.applySplitChunksConfig;
|
|
54
|
-
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
55
|
-
"applySplitChunksConfig"
|
|
56
|
-
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
57
|
-
Object.defineProperty(exports, '__esModule', {
|
|
58
|
-
value: true
|
|
59
|
-
});
|
package/dist/splitChunks.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import 'module';
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
3
|
-
import { isDevServer } from "@unpackjs/core";
|
|
4
|
-
const applySplitChunksConfig = ({ config, unpackConfig })=>{
|
|
5
|
-
if ('split-by-experience' !== unpackConfig.performance.chunkSplit.strategy) return config;
|
|
6
|
-
const currentConfig = config.optimization.splitChunks;
|
|
7
|
-
const extraGroups = {};
|
|
8
|
-
extraGroups.react = {
|
|
9
|
-
name: 'lib-react',
|
|
10
|
-
test: isDevServer() ? /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/,
|
|
11
|
-
priority: 0
|
|
12
|
-
};
|
|
13
|
-
extraGroups.router = {
|
|
14
|
-
name: 'lib-router',
|
|
15
|
-
test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
|
|
16
|
-
priority: 0
|
|
17
|
-
};
|
|
18
|
-
config.optimization.splitChunks = {
|
|
19
|
-
...currentConfig,
|
|
20
|
-
cacheGroups: {
|
|
21
|
-
...extraGroups,
|
|
22
|
-
...currentConfig.cacheGroups
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
return config;
|
|
26
|
-
};
|
|
27
|
-
export { applySplitChunksConfig };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|