@_tc/template-core 0.0.1-bate.15 → 0.0.1-bate.17
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/cjs/bundler/utils.js +61 -3
- package/esm/bundler/utils.js +62 -4
- package/package.json +1 -1
package/cjs/bundler/utils.js
CHANGED
|
@@ -100,7 +100,7 @@ function entries() {
|
|
|
100
100
|
input[key] = path_1.default.resolve(base, fileHtml);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
// for (const file of
|
|
103
|
+
// for (const file of readdirSync(base)) {
|
|
104
104
|
// if (!file.endsWith(".html")) continue;
|
|
105
105
|
// const key = path.basename(file, ".html");
|
|
106
106
|
// input[key] = path.resolve(base, file);
|
|
@@ -132,15 +132,73 @@ const watchFiles = async (callback) => {
|
|
|
132
132
|
console.log(`watching ${runFEPath}/...`);
|
|
133
133
|
};
|
|
134
134
|
exports.watchFiles = watchFiles;
|
|
135
|
+
/**
|
|
136
|
+
*
|
|
137
|
+
* 1. 在 build 结束后
|
|
138
|
+
* 2. 获取输出目录下的html文件
|
|
139
|
+
* 3. 移动内部的html 至 输出目录的根节点
|
|
140
|
+
*/
|
|
141
|
+
function flattenHtmlPlugin() {
|
|
142
|
+
return {
|
|
143
|
+
name: "flatten-html",
|
|
144
|
+
apply: "build",
|
|
145
|
+
closeBundle() {
|
|
146
|
+
const feDir = outDir();
|
|
147
|
+
if (!(0, fs_1.existsSync)(feDir))
|
|
148
|
+
return;
|
|
149
|
+
// 移动文件
|
|
150
|
+
const htmlFiles = glob.sync("**/*.html", { cwd: feDir });
|
|
151
|
+
for (const file of htmlFiles) {
|
|
152
|
+
const src = path_1.default.join(feDir, file);
|
|
153
|
+
const dest = path_1.default.join(feDir, path_1.default.basename(file));
|
|
154
|
+
if (src !== dest) {
|
|
155
|
+
(0, fs_1.copyFileSync)(src, dest);
|
|
156
|
+
(0, fs_1.unlinkSync)(src);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const parents = [...new Set(htmlFiles.map((f) => path_1.default.dirname(f)))]
|
|
160
|
+
.sort()
|
|
161
|
+
.reverse();
|
|
162
|
+
/**
|
|
163
|
+
*
|
|
164
|
+
* 删除空的目录
|
|
165
|
+
*/
|
|
166
|
+
const delEmptyDir = (pathStr) => {
|
|
167
|
+
const currentDir = (0, fs_1.existsSync)(pathStr) ? (0, fs_1.readdirSync)(pathStr) : [1];
|
|
168
|
+
if (!currentDir.length) {
|
|
169
|
+
(0, fs_1.rmdirSync)(pathStr);
|
|
170
|
+
const pa = pathStr.split(path_1.default.sep).slice(0, -1);
|
|
171
|
+
pa.length && delEmptyDir(pa.join(path_1.default.sep));
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
for (const dir of parents) {
|
|
175
|
+
if (dir && dir !== ".") {
|
|
176
|
+
const fullPath = path_1.default.join(feDir, dir);
|
|
177
|
+
delEmptyDir(fullPath);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
135
183
|
const VBuildFE = async (input) => {
|
|
136
184
|
// 根据入口构建
|
|
137
185
|
await (0, vite_1.build)({
|
|
138
186
|
configFile: false,
|
|
139
|
-
plugins: [
|
|
187
|
+
plugins: [
|
|
188
|
+
(await Promise.resolve().then(() => __importStar(require("@vitejs/plugin-react")))).default(),
|
|
189
|
+
flattenHtmlPlugin(),
|
|
190
|
+
],
|
|
140
191
|
build: {
|
|
141
192
|
outDir: outDir(),
|
|
142
193
|
emptyOutDir: true,
|
|
143
|
-
rollupOptions: {
|
|
194
|
+
rollupOptions: {
|
|
195
|
+
input,
|
|
196
|
+
output: {
|
|
197
|
+
entryFileNames: "frontend/[name].js",
|
|
198
|
+
chunkFileNames: "frontend/[name].js",
|
|
199
|
+
assetFileNames: "frontend/[name].[ext]",
|
|
200
|
+
},
|
|
201
|
+
},
|
|
144
202
|
},
|
|
145
203
|
resolve: {
|
|
146
204
|
alias: {
|
package/esm/bundler/utils.js
CHANGED
|
@@ -2,7 +2,7 @@ import path from "path";
|
|
|
2
2
|
import * as glob from "glob";
|
|
3
3
|
import { build } from "vite";
|
|
4
4
|
import { resolve } from "../packages/utils";
|
|
5
|
-
import { readFileSync, writeFileSync } from "fs";
|
|
5
|
+
import { copyFileSync, existsSync, readdirSync, readFileSync, rmdirSync, unlinkSync, writeFileSync, } from "fs";
|
|
6
6
|
const base = process.cwd();
|
|
7
7
|
// 瞄准输出后的产物路径
|
|
8
8
|
const framePath = path.resolve(__dirname, "../../");
|
|
@@ -59,7 +59,7 @@ export function entries() {
|
|
|
59
59
|
input[key] = path.resolve(base, fileHtml);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
// for (const file of
|
|
62
|
+
// for (const file of readdirSync(base)) {
|
|
63
63
|
// if (!file.endsWith(".html")) continue;
|
|
64
64
|
// const key = path.basename(file, ".html");
|
|
65
65
|
// input[key] = path.resolve(base, file);
|
|
@@ -90,15 +90,73 @@ export const watchFiles = async (callback) => {
|
|
|
90
90
|
});
|
|
91
91
|
console.log(`watching ${runFEPath}/...`);
|
|
92
92
|
};
|
|
93
|
+
/**
|
|
94
|
+
*
|
|
95
|
+
* 1. 在 build 结束后
|
|
96
|
+
* 2. 获取输出目录下的html文件
|
|
97
|
+
* 3. 移动内部的html 至 输出目录的根节点
|
|
98
|
+
*/
|
|
99
|
+
function flattenHtmlPlugin() {
|
|
100
|
+
return {
|
|
101
|
+
name: "flatten-html",
|
|
102
|
+
apply: "build",
|
|
103
|
+
closeBundle() {
|
|
104
|
+
const feDir = outDir();
|
|
105
|
+
if (!existsSync(feDir))
|
|
106
|
+
return;
|
|
107
|
+
// 移动文件
|
|
108
|
+
const htmlFiles = glob.sync("**/*.html", { cwd: feDir });
|
|
109
|
+
for (const file of htmlFiles) {
|
|
110
|
+
const src = path.join(feDir, file);
|
|
111
|
+
const dest = path.join(feDir, path.basename(file));
|
|
112
|
+
if (src !== dest) {
|
|
113
|
+
copyFileSync(src, dest);
|
|
114
|
+
unlinkSync(src);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const parents = [...new Set(htmlFiles.map((f) => path.dirname(f)))]
|
|
118
|
+
.sort()
|
|
119
|
+
.reverse();
|
|
120
|
+
/**
|
|
121
|
+
*
|
|
122
|
+
* 删除空的目录
|
|
123
|
+
*/
|
|
124
|
+
const delEmptyDir = (pathStr) => {
|
|
125
|
+
const currentDir = existsSync(pathStr) ? readdirSync(pathStr) : [1];
|
|
126
|
+
if (!currentDir.length) {
|
|
127
|
+
rmdirSync(pathStr);
|
|
128
|
+
const pa = pathStr.split(path.sep).slice(0, -1);
|
|
129
|
+
pa.length && delEmptyDir(pa.join(path.sep));
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
for (const dir of parents) {
|
|
133
|
+
if (dir && dir !== ".") {
|
|
134
|
+
const fullPath = path.join(feDir, dir);
|
|
135
|
+
delEmptyDir(fullPath);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
93
141
|
export const VBuildFE = async (input) => {
|
|
94
142
|
// 根据入口构建
|
|
95
143
|
await build({
|
|
96
144
|
configFile: false,
|
|
97
|
-
plugins: [
|
|
145
|
+
plugins: [
|
|
146
|
+
(await import("@vitejs/plugin-react")).default(),
|
|
147
|
+
flattenHtmlPlugin(),
|
|
148
|
+
],
|
|
98
149
|
build: {
|
|
99
150
|
outDir: outDir(),
|
|
100
151
|
emptyOutDir: true,
|
|
101
|
-
rollupOptions: {
|
|
152
|
+
rollupOptions: {
|
|
153
|
+
input,
|
|
154
|
+
output: {
|
|
155
|
+
entryFileNames: "frontend/[name].js",
|
|
156
|
+
chunkFileNames: "frontend/[name].js",
|
|
157
|
+
assetFileNames: "frontend/[name].[ext]",
|
|
158
|
+
},
|
|
159
|
+
},
|
|
102
160
|
},
|
|
103
161
|
resolve: {
|
|
104
162
|
alias: {
|