package-build.js 1.32 KB
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,
  files: {}
};

const protocolPages = routes.filter(r => r.protocol);
const allFiles = [`degrade-${pkg.version}.html`, `loading-${pkg.version}.html`].concat(manifest.initial, manifest.async);

const files = 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 = `loading-${pkg.version}.html`;
allFiles.forEach(file => {
  const paths = file.split('/');

  vender.files[paths[paths.length - 1]] = `https:${webpackConfig.output.publicPath}${file}`;
});
vender.pkgfile = `https://cdn.yoho.cn/${pkg.name}/${zipFile}`;
vender.routes = protocolPages.map(p => {
  const routeStr = p.route.toString();

  return {
    route: routeStr.substring(1, routeStr.length - 1),
    template: `degrade-${pkg.version}.html`
  };
});

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