-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundler.js
43 lines (35 loc) · 1.16 KB
/
bundler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const Bundler = require("parcel-bundler");
const path = require("path");
const fs = require("fs-extra");
// 入口文件路径
const file = path.join(__dirname, "./index.html");
const distPath = path.join(__dirname, "./dist");
const modelPath = path.join(__dirname, "model");
const modelDistPath = path.join(distPath, "model");
const dataPath = path.join(__dirname, "data");
const dataDistPath = path.join(distPath, "data");
// Bundler 选项
const options = {
outFile: "index.html", // 输出文件的名称
publicUrl: process.env.NODE_ENV !== "production" ? '/' : './'
};
// 使用提供的入口文件路径和选项初始化 bundler
const bundler = new Bundler(file, options);
bundler.on("bundled", bundler => {
// copy model and train data
if (!fs.existsSync(modelDistPath)) {
fs.mkdirSync(modelDistPath);
fs.copySync(modelPath, modelDistPath);
}
if (!fs.existsSync(dataDistPath)) {
fs.mkdirSync(dataDistPath);
fs.copySync(dataPath, dataDistPath);
}
});
bundler.bundle();
if (process.env.NODE_ENV !== "production") {
const app = require("express")();
app.use(bundler.middleware());
app.listen(1234);
console.log("listion port: 1234");
}