package-build.js
1.15 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
};
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'
});