-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparcel.config.js
60 lines (48 loc) · 1.27 KB
/
parcel.config.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const Bundler = require('parcel-bundler');
const {
rm,
cp,
mkdir,
exec,
echo
} = require('shelljs');
const chalk = require('chalk');
const Path = require('path');
const glob = require("glob");
const isPrd = process.env.NODE_ENV === 'production';
// 打包文件输出目录
let dir = isPrd ? '/prd' : '/dev';
let outDir = './dist' + dir;
// 打包配置
const options = {
outDir: outDir + '/pages',
publicURL: '../',
hmr: false,
// cache: true,
sourceMaps: false
};
// 遍历打包目录函数
function entries(globPath) {
let files = [];
globPath.forEach(function(item) {
[].forEach.call(glob.sync(item), function(filePath) {
files.push(filePath);
});
});
return files;
}
// 遍历需要打包的页面目录
const pages = entries(["./src/app/**/*.html"]);
const bundler = new Bundler(pages, options);
async function bundle() {
await bundler.bundle();
}
// 开始打包
bundle().then((data) => {
console.log(chalk.yellow("\n拷贝 /unpackage"));
mkdir('-p', outDir + "/unpackage/res");
cp("-r", "unpackage/res/*", outDir + "/unpackage/res");
console.log(chalk.yellow("拷贝 /manifest.json"));
cp("-r", "manifest.json", outDir);
console.log(chalk.green("执行完成 \n"));
});