@_tc/template-core 0.0.1-bate.14 → 0.0.1-bate.16

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.
@@ -2,14 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dev = dev;
4
4
  const utils_1 = require("./utils");
5
- async function dev() {
6
- // 获取入口
5
+ const init = async () => {
7
6
  const input = (0, utils_1.entries)();
7
+ console.log(input);
8
8
  if (!Object.keys(input).length) {
9
9
  console.error("no entry found");
10
10
  process.exit(1);
11
11
  }
12
12
  await (0, utils_1.VBuildFE)(input);
13
+ };
14
+ async function dev() {
15
+ // 获取入口
16
+ await init();
13
17
  // 监听文件变化
14
- (0, utils_1.watchFiles)(async () => (0, utils_1.VBuildFE)(input));
18
+ (0, utils_1.watchFiles)(async () => init());
15
19
  }
@@ -108,8 +108,8 @@ function entries() {
108
108
  return input;
109
109
  }
110
110
  function outDir() {
111
- // 为了保持代码 能见性 输出地址应该为 runPath/app/publish/dist
112
- return path_1.default.join(runPath, "./app/publish/dist");
111
+ // 为了保持代码 能见性 输出地址应该为 runPath/app/public/dist
112
+ return path_1.default.join(runPath, "./app/public/dist");
113
113
  }
114
114
  const watchFiles = async (callback) => {
115
115
  const chokidar = await Promise.resolve().then(() => __importStar(require("chokidar")));
@@ -132,15 +132,39 @@ const watchFiles = async (callback) => {
132
132
  console.log(`watching ${runFEPath}/...`);
133
133
  };
134
134
  exports.watchFiles = watchFiles;
135
+ const customOutputPlugin = {
136
+ name: "custom-output-paths",
137
+ generateBundle(_, bundle) {
138
+ for (const [fileName, chunk] of Object.entries(bundle)) {
139
+ if (!fileName.endsWith(".html"))
140
+ continue;
141
+ const baseName = path_1.default.basename(fileName);
142
+ const desiredName = `frontend/${baseName}`;
143
+ delete bundle[fileName];
144
+ chunk.fileName = desiredName;
145
+ bundle[desiredName] = chunk;
146
+ }
147
+ },
148
+ };
135
149
  const VBuildFE = async (input) => {
136
150
  // 根据入口构建
137
151
  await (0, vite_1.build)({
138
152
  configFile: false,
139
- plugins: [(await Promise.resolve().then(() => __importStar(require("@vitejs/plugin-react")))).default()],
153
+ plugins: [
154
+ (await Promise.resolve().then(() => __importStar(require("@vitejs/plugin-react")))).default(),
155
+ customOutputPlugin,
156
+ ],
140
157
  build: {
141
158
  outDir: outDir(),
142
159
  emptyOutDir: true,
143
- rollupOptions: { input },
160
+ rollupOptions: {
161
+ input,
162
+ output: {
163
+ entryFileNames: "frontend/[name].js",
164
+ chunkFileNames: "frontend/[name].js",
165
+ assetFileNames: "frontend/[name].[ext]",
166
+ },
167
+ },
144
168
  },
145
169
  resolve: {
146
170
  alias: {
@@ -1,12 +1,16 @@
1
1
  import { entries, VBuildFE, watchFiles } from "./utils";
2
- export async function dev() {
3
- // 获取入口
2
+ const init = async () => {
4
3
  const input = entries();
4
+ console.log(input);
5
5
  if (!Object.keys(input).length) {
6
6
  console.error("no entry found");
7
7
  process.exit(1);
8
8
  }
9
9
  await VBuildFE(input);
10
+ };
11
+ export async function dev() {
12
+ // 获取入口
13
+ await init();
10
14
  // 监听文件变化
11
- watchFiles(async () => VBuildFE(input));
15
+ watchFiles(async () => init());
12
16
  }
@@ -67,8 +67,8 @@ export function entries() {
67
67
  return input;
68
68
  }
69
69
  export function outDir() {
70
- // 为了保持代码 能见性 输出地址应该为 runPath/app/publish/dist
71
- return path.join(runPath, "./app/publish/dist");
70
+ // 为了保持代码 能见性 输出地址应该为 runPath/app/public/dist
71
+ return path.join(runPath, "./app/public/dist");
72
72
  }
73
73
  export const watchFiles = async (callback) => {
74
74
  const chokidar = await import("chokidar");
@@ -90,15 +90,39 @@ export const watchFiles = async (callback) => {
90
90
  });
91
91
  console.log(`watching ${runFEPath}/...`);
92
92
  };
93
+ const customOutputPlugin = {
94
+ name: "custom-output-paths",
95
+ generateBundle(_, bundle) {
96
+ for (const [fileName, chunk] of Object.entries(bundle)) {
97
+ if (!fileName.endsWith(".html"))
98
+ continue;
99
+ const baseName = path.basename(fileName);
100
+ const desiredName = `frontend/${baseName}`;
101
+ delete bundle[fileName];
102
+ chunk.fileName = desiredName;
103
+ bundle[desiredName] = chunk;
104
+ }
105
+ },
106
+ };
93
107
  export const VBuildFE = async (input) => {
94
108
  // 根据入口构建
95
109
  await build({
96
110
  configFile: false,
97
- plugins: [(await import("@vitejs/plugin-react")).default()],
111
+ plugins: [
112
+ (await import("@vitejs/plugin-react")).default(),
113
+ customOutputPlugin,
114
+ ],
98
115
  build: {
99
116
  outDir: outDir(),
100
117
  emptyOutDir: true,
101
- rollupOptions: { input },
118
+ rollupOptions: {
119
+ input,
120
+ output: {
121
+ entryFileNames: "frontend/[name].js",
122
+ chunkFileNames: "frontend/[name].js",
123
+ assetFileNames: "frontend/[name].[ext]",
124
+ },
125
+ },
102
126
  },
103
127
  resolve: {
104
128
  alias: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@_tc/template-core",
3
- "version": "0.0.1-bate.14",
3
+ "version": "0.0.1-bate.16",
4
4
  "description": "A TypeScript Koa framework template - Monorepo root",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",