UNPKG

1.35 kBJavaScriptView Raw
1import fs from "fs";
2import path from "path";
3import glob from "glob";
4import utils from "node-pearls";
5
6export default function(options){
7 const root = process.cwd();
8 const bundleDir = path.join(root, "web", options.platform, "bundle");
9
10 console.log("生成依赖关系表");
11
12 glob("*/deps.json", {
13 cwd: bundleDir
14 }, function(err, jsons){
15 if(err){
16 throw err;
17 }
18
19 var files = [];
20
21 jsons.forEach(function(file){
22 var json = utils.readJson.sync(path.join(bundleDir, file));
23 files = files.concat(json.files);
24 });
25
26 fs.writeFileSync(path.join(bundleDir, "deps.json"), JSON.stringify({
27 files: files
28 }));
29
30 console.log("拷贝资源文件");
31
32 var assetsDir = path.join(bundleDir, "assets");
33 utils.mkdirs.sync(assetsDir);
34 // 拷贝资源
35 glob("*/*.@(gif|jpg|png|woff|svg|eot|ttf)", {
36 cwd: bundleDir
37 }, function(err, assets){
38 utils.copyFiles(assets.map(function(asset){
39 return {
40 src: path.join(bundleDir, asset),
41 dist: path.join(assetsDir, asset.split("/").pop())
42 };
43 })).then(function(){
44 console.log("打包完成");
45 });
46 });
47 });
48}
\No newline at end of file