Blame view

build/package-build.js 1.15 KB
陈峰 authored
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
const routes = require('../config/ssr-routes');
const manifest = require('../dist/manifest.json');
const shelljs = require('shelljs');
const fs = require('fs');
const path = require('path');
const pkg = require('../package.json');
const webpackConfig = require('./webpack.base.conf');
const dir = path.join(__dirname, '../dist/statics/yoho-community-web');
const vender = {
  version: pkg.version
};

const protocolPages = routes.filter(r => r.protocol);
const allFiles = [].concat(manifest.initial, manifest.async);

const files = ['../../degrade.html'].concat(allFiles).map(file => path.join(dir, file)).join(' ');
const zipFile = `${pkg.version}.zip`;

shelljs.exec(`zip -j -q ${path.join(dir, zipFile)} ${files}`);

vender.default = 'yoho-protocol://m.yohobuy.com/grass/default';
vender.files = allFiles.map(file => `https:${webpackConfig.output.publicPath}${file}`);
vender.pkgfile = `https://cdn.yoho.cn/yoho-community-web/static/${zipFile}`;
vender.routes = protocolPages.map(p => {
  return {
    route: p.route.toString(),
    template: 'degrade.html'
  };
});

fs.writeFileSync(path.join(dir, 'pkg.json'), JSON.stringify(vender, void 0, 2), {
  encoding: 'utf-8'
});