@unpackjs/plugin-react 1.7.5 → 1.7.7

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/mpa.cjs CHANGED
@@ -1,150 +1,156 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var mpa_exports = {};
29
- __export(mpa_exports, {
30
- applyMpaConfig: () => applyMpaConfig
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = function(module) {
5
+ var getter = module && module.__esModule ? function() {
6
+ return module['default'];
7
+ } : function() {
8
+ return module;
9
+ };
10
+ __webpack_require__.d(getter, {
11
+ a: getter
12
+ });
13
+ return getter;
14
+ };
15
+ })();
16
+ (()=>{
17
+ __webpack_require__.d = function(exports1, definition) {
18
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
19
+ enumerable: true,
20
+ get: definition[key]
21
+ });
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = function(obj, prop) {
26
+ return Object.prototype.hasOwnProperty.call(obj, prop);
27
+ };
28
+ })();
29
+ (()=>{
30
+ __webpack_require__.r = function(exports1) {
31
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
32
+ value: 'Module'
33
+ });
34
+ Object.defineProperty(exports1, '__esModule', {
35
+ value: true
36
+ });
37
+ };
38
+ })();
39
+ var __webpack_exports__ = {};
40
+ __webpack_require__.r(__webpack_exports__);
41
+ __webpack_require__.d(__webpack_exports__, {
42
+ applyMpaConfig: ()=>applyMpaConfig
31
43
  });
32
- module.exports = __toCommonJS(mpa_exports);
33
- var import_node_fs = __toESM(require("node:fs"));
34
- var import_node_path = __toESM(require("node:path"));
35
- var import_core = require("@unpackjs/core");
36
- const applyMpaConfig = ({
37
- config,
38
- unpackConfig,
39
- mergeConfig,
40
- HtmlPlugin
41
- }) => {
42
- if (!unpackConfig.mpa)
43
- return config;
44
- const isRspack = unpackConfig.bundler === "rspack";
45
- const tempDirectory = import_node_path.default.join(import_core.TEMP_DIR, "mpa");
46
- const userOptions = (0, import_core.isPlainObject)(unpackConfig.mpa) ? unpackConfig.mpa : {};
47
- const getPageConfig = (indexPath) => {
48
- const filePath = import_node_path.default.join(indexPath, "../config.json");
49
- let pageConfig = {};
50
- if (import_node_fs.default.existsSync(filePath)) {
51
- pageConfig = JSON.parse(import_node_fs.default.readFileSync(filePath, "utf-8"));
52
- }
53
- return pageConfig;
54
- };
55
- const createTempFile = (entry2) => {
56
- (0, import_core.removeDir)(import_node_path.default.join(unpackConfig.root, tempDirectory));
57
- const globalImport = userOptions.globalImport?.reduce((acc, curr) => {
58
- return `${acc}
59
- import '${(0, import_core.getPathInJs)(import_node_path.default.resolve(unpackConfig.root, curr))}'`;
60
- }, "") || "";
61
- const { layout } = userOptions;
62
- const layoutImport = layout ? `import Layout from '${(0, import_core.getPathInJs)(import_node_path.default.resolve(unpackConfig.root, layout))}'` : "";
63
- const layoutJSX = layout ? "<Layout><App /></Layout>" : "<App />";
64
- const rootElement = `document.getElementById('${unpackConfig.html?.mountId}')`;
65
- const reactDOMSource = "react-dom/client";
66
- const renderer = `ReactDOM.createRoot(${rootElement}).render(${layoutJSX})`;
67
- Object.entries(entry2).forEach(([entryName, entryConfig]) => {
68
- const filePath = import_node_path.default.join(unpackConfig.root, tempDirectory, `${entryName}.jsx`);
69
- const tpl = `
44
+ const external_node_fs_namespaceObject = require("node:fs");
45
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
46
+ const external_node_path_namespaceObject = require("node:path");
47
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
48
+ const core_namespaceObject = require("@unpackjs/core");
49
+ const applyMpaConfig = ({ config, unpackConfig, mergeConfig, HtmlPlugin })=>{
50
+ if (!unpackConfig.mpa) return config;
51
+ const isRspack = 'rspack' === unpackConfig.bundler;
52
+ const tempDirectory = external_node_path_default().join(core_namespaceObject.TEMP_DIR, 'mpa');
53
+ const userOptions = (0, core_namespaceObject.isPlainObject)(unpackConfig.mpa) ? unpackConfig.mpa : {};
54
+ const getPageConfig = (indexPath)=>{
55
+ const filePath = external_node_path_default().join(indexPath, '../config.json');
56
+ let pageConfig = {};
57
+ if (external_node_fs_default().existsSync(filePath)) pageConfig = JSON.parse(external_node_fs_default().readFileSync(filePath, 'utf-8'));
58
+ return pageConfig;
59
+ };
60
+ const createTempFile = (entry)=>{
61
+ var _userOptions_globalImport, _unpackConfig_html;
62
+ (0, core_namespaceObject.removeDir)(external_node_path_default().join(unpackConfig.root, tempDirectory));
63
+ const globalImport = (null === (_userOptions_globalImport = userOptions.globalImport) || void 0 === _userOptions_globalImport ? void 0 : _userOptions_globalImport.reduce((acc, curr)=>`${acc}\nimport '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().resolve(unpackConfig.root, curr))}'`, '')) || '';
64
+ const { layout } = userOptions;
65
+ const layoutImport = layout ? `import Layout from '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().resolve(unpackConfig.root, layout))}'` : '';
66
+ const layoutJSX = layout ? '<Layout><App /></Layout>' : '<App />';
67
+ const rootElement = `document.getElementById('${null === (_unpackConfig_html = unpackConfig.html) || void 0 === _unpackConfig_html ? void 0 : _unpackConfig_html.mountId}')`;
68
+ const reactDOMSource = 'react-dom/client';
69
+ const renderer = `ReactDOM.createRoot(${rootElement}).render(${layoutJSX})`;
70
+ Object.entries(entry).forEach(([entryName, entryConfig])=>{
71
+ const filePath = external_node_path_default().join(unpackConfig.root, tempDirectory, `${entryName}.jsx`);
72
+ const tpl = `
70
73
  import React from 'react'
71
74
  import ReactDOM from '${reactDOMSource}'
72
- import App from '${(0, import_core.getPathInJs)(entryConfig.import[0])}'${layoutImport && `
73
- ${layoutImport}`}
75
+ import App from '${(0, core_namespaceObject.getPathInJs)(entryConfig.import[0])}'${layoutImport && `\n${layoutImport}`}
74
76
  ${globalImport}
75
77
  ${renderer}
76
78
  `;
77
- const dir = import_node_path.default.dirname(filePath);
78
- if (!import_node_fs.default.existsSync(dir)) {
79
- import_node_fs.default.mkdirSync(dir, { recursive: true });
80
- }
81
- import_node_fs.default.writeFileSync(filePath, tpl, "utf-8");
82
- entryConfig.import[0] = filePath;
83
- });
84
- return entry2;
85
- };
86
- const collectEntry = () => {
87
- const start = performance.now();
88
- const entry2 = {};
89
- const html2 = [];
90
- const getIndexFilePath = (dir) => {
91
- const extensions = [".tsx", ".jsx"];
92
- for (const extension of extensions) {
93
- const indexFilePath = import_node_path.default.join(dir, `index${extension}`);
94
- if (import_node_fs.default.existsSync(indexFilePath)) {
95
- return indexFilePath;
96
- }
97
- }
98
- return null;
79
+ const dir = external_node_path_default().dirname(filePath);
80
+ if (!external_node_fs_default().existsSync(dir)) external_node_fs_default().mkdirSync(dir, {
81
+ recursive: true
82
+ });
83
+ external_node_fs_default().writeFileSync(filePath, tpl, 'utf-8');
84
+ entryConfig.import[0] = filePath;
85
+ });
86
+ return entry;
99
87
  };
100
- const pagesRoot = import_node_path.default.join(unpackConfig.root, "src", "pages");
101
- import_node_fs.default.readdirSync(pagesRoot).forEach((filename) => {
102
- if (filename.startsWith("."))
103
- return;
104
- const indexFilePath = getIndexFilePath(import_node_path.default.join(pagesRoot, filename));
105
- if (indexFilePath) {
106
- const pageConfig = getPageConfig(indexFilePath);
107
- let entryName = userOptions.lowerCase === true ? filename.toLowerCase() : filename;
108
- if (pageConfig.filename) {
109
- entryName = pageConfig.filename.slice(0, -5);
110
- }
111
- entry2[entryName] = {
112
- import: [indexFilePath]
88
+ const collectEntry = ()=>{
89
+ const start = performance.now();
90
+ const entry = {};
91
+ const html = [];
92
+ const getIndexFilePath = (dir)=>{
93
+ const extensions = [
94
+ '.tsx',
95
+ '.jsx'
96
+ ];
97
+ for (const extension of extensions){
98
+ const indexFilePath = external_node_path_default().join(dir, `index${extension}`);
99
+ if (external_node_fs_default().existsSync(indexFilePath)) return indexFilePath;
100
+ }
101
+ return null;
113
102
  };
114
- if (pageConfig.template) {
115
- pageConfig.template = import_node_path.default.join(indexFilePath, "../", pageConfig.template);
116
- }
117
- html2.push({
118
- template: unpackConfig.html?.template || (isRspack ? void 0 : ""),
119
- // @ts-expect-error
120
- templateContent: unpackConfig.html?.templateContent || (!unpackConfig.html?.template ? import_core.TEMPLATE_CONTENT : isRspack ? void 0 : false),
121
- minify: false,
122
- filename: `${entryName}.html`,
123
- chunks: [entryName],
124
- ...pageConfig,
125
- templateParameters: {
126
- mountId: unpackConfig.html?.mountId,
127
- title: (0, import_core.isFunction)(unpackConfig.html?.title) ? unpackConfig.html?.title({ entryName }) : unpackConfig.html?.title || "",
128
- headTag: unpackConfig.html?.headTag || "",
129
- ...unpackConfig.html?.templateParameters,
130
- ...pageConfig.templateParameters
131
- }
103
+ const pagesRoot = external_node_path_default().join(unpackConfig.root, 'src', 'pages');
104
+ external_node_fs_default().readdirSync(pagesRoot).forEach((filename)=>{
105
+ if (filename.startsWith('.')) return;
106
+ const indexFilePath = getIndexFilePath(external_node_path_default().join(pagesRoot, filename));
107
+ if (indexFilePath) {
108
+ var _unpackConfig_html, _unpackConfig_html1, _unpackConfig_html2, _unpackConfig_html3, _unpackConfig_html4, _unpackConfig_html5, _unpackConfig_html6, _unpackConfig_html7, _unpackConfig_html8;
109
+ const pageConfig = getPageConfig(indexFilePath);
110
+ let entryName = true === userOptions.lowerCase ? filename.toLowerCase() : filename;
111
+ if (pageConfig.filename) entryName = pageConfig.filename.slice(0, -5);
112
+ entry[entryName] = {
113
+ import: [
114
+ indexFilePath
115
+ ]
116
+ };
117
+ if (pageConfig.template) pageConfig.template = external_node_path_default().join(indexFilePath, '../', pageConfig.template);
118
+ html.push({
119
+ template: (null === (_unpackConfig_html = unpackConfig.html) || void 0 === _unpackConfig_html ? void 0 : _unpackConfig_html.template) || (isRspack ? void 0 : ''),
120
+ templateContent: (null === (_unpackConfig_html1 = unpackConfig.html) || void 0 === _unpackConfig_html1 ? void 0 : _unpackConfig_html1.templateContent) || ((null === (_unpackConfig_html2 = unpackConfig.html) || void 0 === _unpackConfig_html2 ? void 0 : _unpackConfig_html2.template) ? isRspack ? void 0 : false : core_namespaceObject.TEMPLATE_CONTENT),
121
+ minify: false,
122
+ filename: `${entryName}.html`,
123
+ chunks: [
124
+ entryName
125
+ ],
126
+ ...pageConfig,
127
+ templateParameters: {
128
+ mountId: null === (_unpackConfig_html3 = unpackConfig.html) || void 0 === _unpackConfig_html3 ? void 0 : _unpackConfig_html3.mountId,
129
+ title: (0, core_namespaceObject.isFunction)(null === (_unpackConfig_html4 = unpackConfig.html) || void 0 === _unpackConfig_html4 ? void 0 : _unpackConfig_html4.title) ? null === (_unpackConfig_html5 = unpackConfig.html) || void 0 === _unpackConfig_html5 ? void 0 : _unpackConfig_html5.title({
130
+ entryName
131
+ }) : (null === (_unpackConfig_html6 = unpackConfig.html) || void 0 === _unpackConfig_html6 ? void 0 : _unpackConfig_html6.title) || '',
132
+ headTag: (null === (_unpackConfig_html7 = unpackConfig.html) || void 0 === _unpackConfig_html7 ? void 0 : _unpackConfig_html7.headTag) || '',
133
+ ...null === (_unpackConfig_html8 = unpackConfig.html) || void 0 === _unpackConfig_html8 ? void 0 : _unpackConfig_html8.templateParameters,
134
+ ...pageConfig.templateParameters
135
+ }
136
+ });
137
+ }
132
138
  });
133
- }
139
+ (0, core_namespaceObject.isDevServer)() || core_namespaceObject.logger.info(`Collect entries in ${(performance.now() - start).toFixed(2)}ms ${core_namespaceObject.colors.dim('[MPA]')}`);
140
+ return {
141
+ entry,
142
+ html
143
+ };
144
+ };
145
+ const { entry, html } = collectEntry();
146
+ config = mergeConfig(config, {
147
+ entry: createTempFile(entry),
148
+ plugins: html.map((h)=>new HtmlPlugin(h))
134
149
  });
135
- !(0, import_core.isDevServer)() && import_core.logger.info(
136
- `Collect entries in ${(performance.now() - start).toFixed(2)}ms ${import_core.colors.dim("[MPA]")}`
137
- );
138
- return { entry: entry2, html: html2 };
139
- };
140
- const { entry, html } = collectEntry();
141
- config = mergeConfig(config, {
142
- entry: createTempFile(entry),
143
- plugins: html.map((h) => new HtmlPlugin(h))
144
- });
145
- return config;
150
+ return config;
146
151
  };
147
- // Annotate the CommonJS export names for ESM import in node:
148
- 0 && (module.exports = {
149
- applyMpaConfig
152
+ var __webpack_export_target__ = exports;
153
+ for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
154
+ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
155
+ value: true
150
156
  });
package/dist/mpa.js CHANGED
@@ -1,136 +1,109 @@
1
- import { createRequire } from 'node:module';
2
- var require = createRequire(import.meta['url']);
3
-
4
- import path from "path";
5
- import { fileURLToPath } from "url";
6
- var getFilename = () => fileURLToPath(import.meta.url);
7
- var getDirname = () => path.dirname(getFilename());
8
- var __dirname = /* @__PURE__ */ getDirname();
9
- var __filename = /* @__PURE__ */ getFilename();
10
- import fs from "node:fs";
11
- import path2 from "node:path";
12
- import {
13
- TEMPLATE_CONTENT,
14
- TEMP_DIR,
15
- colors,
16
- getPathInJs,
17
- isDevServer,
18
- isFunction,
19
- isPlainObject,
20
- logger,
21
- removeDir
22
- } from "@unpackjs/core";
23
- const applyMpaConfig = ({
24
- config,
25
- unpackConfig,
26
- mergeConfig,
27
- HtmlPlugin
28
- }) => {
29
- if (!unpackConfig.mpa)
30
- return config;
31
- const isRspack = unpackConfig.bundler === "rspack";
32
- const tempDirectory = path2.join(TEMP_DIR, "mpa");
33
- const userOptions = isPlainObject(unpackConfig.mpa) ? unpackConfig.mpa : {};
34
- const getPageConfig = (indexPath) => {
35
- const filePath = path2.join(indexPath, "../config.json");
36
- let pageConfig = {};
37
- if (fs.existsSync(filePath)) {
38
- pageConfig = JSON.parse(fs.readFileSync(filePath, "utf-8"));
39
- }
40
- return pageConfig;
41
- };
42
- const createTempFile = (entry2) => {
43
- removeDir(path2.join(unpackConfig.root, tempDirectory));
44
- const globalImport = userOptions.globalImport?.reduce((acc, curr) => {
45
- return `${acc}
46
- import '${getPathInJs(path2.resolve(unpackConfig.root, curr))}'`;
47
- }, "") || "";
48
- const { layout } = userOptions;
49
- const layoutImport = layout ? `import Layout from '${getPathInJs(path2.resolve(unpackConfig.root, layout))}'` : "";
50
- const layoutJSX = layout ? "<Layout><App /></Layout>" : "<App />";
51
- const rootElement = `document.getElementById('${unpackConfig.html?.mountId}')`;
52
- const reactDOMSource = "react-dom/client";
53
- const renderer = `ReactDOM.createRoot(${rootElement}).render(${layoutJSX})`;
54
- Object.entries(entry2).forEach(([entryName, entryConfig]) => {
55
- const filePath = path2.join(unpackConfig.root, tempDirectory, `${entryName}.jsx`);
56
- const tpl = `
1
+ import __rslib_shim_module__ from 'module';
2
+ /*#__PURE__*/ import.meta.url;
3
+ import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
4
+ import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
5
+ import * as __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__ 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 = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(__WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.TEMP_DIR, 'mpa');
10
+ const userOptions = (0, __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.isPlainObject)(unpackConfig.mpa) ? unpackConfig.mpa : {};
11
+ const getPageConfig = (indexPath)=>{
12
+ const filePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(indexPath, '../config.json');
13
+ let pageConfig = {};
14
+ if (__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(filePath)) pageConfig = JSON.parse(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(filePath, 'utf-8'));
15
+ return pageConfig;
16
+ };
17
+ const createTempFile = (entry)=>{
18
+ var _userOptions_globalImport, _unpackConfig_html;
19
+ (0, __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.removeDir)(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(unpackConfig.root, tempDirectory));
20
+ const globalImport = (null === (_userOptions_globalImport = userOptions.globalImport) || void 0 === _userOptions_globalImport ? void 0 : _userOptions_globalImport.reduce((acc, curr)=>`${acc}\nimport '${(0, __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.getPathInJs)(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(unpackConfig.root, curr))}'`, '')) || '';
21
+ const { layout } = userOptions;
22
+ const layoutImport = layout ? `import Layout from '${(0, __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.getPathInJs)(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].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 ? 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 = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(unpackConfig.root, tempDirectory, `${entryName}.jsx`);
29
+ const tpl = `
57
30
  import React from 'react'
58
31
  import ReactDOM from '${reactDOMSource}'
59
- import App from '${getPathInJs(entryConfig.import[0])}'${layoutImport && `
60
- ${layoutImport}`}
32
+ import App from '${(0, __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.getPathInJs)(entryConfig.import[0])}'${layoutImport && `\n${layoutImport}`}
61
33
  ${globalImport}
62
34
  ${renderer}
63
35
  `;
64
- const dir = path2.dirname(filePath);
65
- if (!fs.existsSync(dir)) {
66
- fs.mkdirSync(dir, { recursive: true });
67
- }
68
- fs.writeFileSync(filePath, tpl, "utf-8");
69
- entryConfig.import[0] = filePath;
70
- });
71
- return entry2;
72
- };
73
- const collectEntry = () => {
74
- const start = performance.now();
75
- const entry2 = {};
76
- const html2 = [];
77
- const getIndexFilePath = (dir) => {
78
- const extensions = [".tsx", ".jsx"];
79
- for (const extension of extensions) {
80
- const indexFilePath = path2.join(dir, `index${extension}`);
81
- if (fs.existsSync(indexFilePath)) {
82
- return indexFilePath;
83
- }
84
- }
85
- return null;
36
+ const dir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(filePath);
37
+ if (!__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(dir)) __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].mkdirSync(dir, {
38
+ recursive: true
39
+ });
40
+ __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].writeFileSync(filePath, tpl, 'utf-8');
41
+ entryConfig.import[0] = filePath;
42
+ });
43
+ return entry;
86
44
  };
87
- const pagesRoot = path2.join(unpackConfig.root, "src", "pages");
88
- fs.readdirSync(pagesRoot).forEach((filename) => {
89
- if (filename.startsWith("."))
90
- return;
91
- const indexFilePath = getIndexFilePath(path2.join(pagesRoot, filename));
92
- if (indexFilePath) {
93
- const pageConfig = getPageConfig(indexFilePath);
94
- let entryName = userOptions.lowerCase === true ? filename.toLowerCase() : filename;
95
- if (pageConfig.filename) {
96
- entryName = pageConfig.filename.slice(0, -5);
97
- }
98
- entry2[entryName] = {
99
- import: [indexFilePath]
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 = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(dir, `index${extension}`);
56
+ if (__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(indexFilePath)) return indexFilePath;
57
+ }
58
+ return null;
100
59
  };
101
- if (pageConfig.template) {
102
- pageConfig.template = path2.join(indexFilePath, "../", pageConfig.template);
103
- }
104
- html2.push({
105
- template: unpackConfig.html?.template || (isRspack ? void 0 : ""),
106
- // @ts-expect-error
107
- templateContent: unpackConfig.html?.templateContent || (!unpackConfig.html?.template ? TEMPLATE_CONTENT : isRspack ? void 0 : false),
108
- minify: false,
109
- filename: `${entryName}.html`,
110
- chunks: [entryName],
111
- ...pageConfig,
112
- templateParameters: {
113
- mountId: unpackConfig.html?.mountId,
114
- title: isFunction(unpackConfig.html?.title) ? unpackConfig.html?.title({ entryName }) : unpackConfig.html?.title || "",
115
- headTag: unpackConfig.html?.headTag || "",
116
- ...unpackConfig.html?.templateParameters,
117
- ...pageConfig.templateParameters
118
- }
60
+ const pagesRoot = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(unpackConfig.root, 'src', 'pages');
61
+ __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readdirSync(pagesRoot).forEach((filename)=>{
62
+ if (filename.startsWith('.')) return;
63
+ const indexFilePath = getIndexFilePath(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].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 = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(indexFilePath, '../', pageConfig.template);
75
+ html.push({
76
+ template: (null === (_unpackConfig_html = unpackConfig.html) || void 0 === _unpackConfig_html ? void 0 : _unpackConfig_html.template) || (isRspack ? void 0 : ''),
77
+ templateContent: (null === (_unpackConfig_html1 = unpackConfig.html) || void 0 === _unpackConfig_html1 ? void 0 : _unpackConfig_html1.templateContent) || ((null === (_unpackConfig_html2 = unpackConfig.html) || void 0 === _unpackConfig_html2 ? void 0 : _unpackConfig_html2.template) ? isRspack ? void 0 : false : __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.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 ? void 0 : _unpackConfig_html3.mountId,
86
+ title: (0, __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.isFunction)(null === (_unpackConfig_html4 = unpackConfig.html) || void 0 === _unpackConfig_html4 ? void 0 : _unpackConfig_html4.title) ? null === (_unpackConfig_html5 = unpackConfig.html) || void 0 === _unpackConfig_html5 ? void 0 : _unpackConfig_html5.title({
87
+ entryName
88
+ }) : (null === (_unpackConfig_html6 = unpackConfig.html) || void 0 === _unpackConfig_html6 ? void 0 : _unpackConfig_html6.title) || '',
89
+ headTag: (null === (_unpackConfig_html7 = unpackConfig.html) || void 0 === _unpackConfig_html7 ? void 0 : _unpackConfig_html7.headTag) || '',
90
+ ...null === (_unpackConfig_html8 = unpackConfig.html) || void 0 === _unpackConfig_html8 ? void 0 : _unpackConfig_html8.templateParameters,
91
+ ...pageConfig.templateParameters
92
+ }
93
+ });
94
+ }
119
95
  });
120
- }
96
+ (0, __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.isDevServer)() || __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.logger.info(`Collect entries in ${(performance.now() - start).toFixed(2)}ms ${__WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.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))
121
106
  });
122
- !isDevServer() && logger.info(
123
- `Collect entries in ${(performance.now() - start).toFixed(2)}ms ${colors.dim("[MPA]")}`
124
- );
125
- return { entry: entry2, html: html2 };
126
- };
127
- const { entry, html } = collectEntry();
128
- config = mergeConfig(config, {
129
- entry: createTempFile(entry),
130
- plugins: html.map((h) => new HtmlPlugin(h))
131
- });
132
- return config;
133
- };
134
- export {
135
- applyMpaConfig
107
+ return config;
136
108
  };
109
+ export { applyMpaConfig };