Open tjswk2008 opened 5 years ago
app.post('/generate', (req, res) => { // delete require.cache['./build/webpack.client.config.js']; // const clientWebpackConfig = require('./build/webpack.client.config.js') getBundle(compilersOptions[0]) // Promise.all(compilersOptions.map(config => getBundle(config))) .then(() => { const config = require('./routes.config'); return getRoutes(config.routesSample) }) .then(result => { console.log(result); let promiseArr = result.map(x => renderCoreAsync(x, './src/index.template.html', false))
return Promise.all(promiseArr); }) .then(() => { console.log('==========html generated=========='); res.sendStatus(200); });
});
function getBundle(config) { return new Promise((resolve, reject) => { process.env.NODE_ENV = 'production'; child_process.exec('npm run build', function (error, stdout, stderr) { if (error) { console.error('error: ' + error); reject(); } resolve(); }); }); }
function renderCoreAsync(url, templateSrc, pure) { return new Promise((resolve, reject) => { const context = { title: 'Vue HN 2.0', // default title url: url, pure: pure } if(!fs.existsSync(baseUrl)) { fs.mkdirSync(baseUrl); } const template = fs.readFileSync(templateSrc, 'utf-8') delete require.cache['./dist/vue-ssr-server-bundle.json']; const bundle = require('./dist/vue-ssr-server-bundle.json') // The client manifests are optional, but it allows the renderer // to automatically infer preload/prefetch links and directly add Githubissues.
app.post('/generate', (req, res) => { // delete require.cache['./build/webpack.client.config.js']; // const clientWebpackConfig = require('./build/webpack.client.config.js') getBundle(compilersOptions[0]) // Promise.all(compilersOptions.map(config => getBundle(config))) .then(() => { const config = require('./routes.config'); return getRoutes(config.routesSample) }) .then(result => { console.log(result); let promiseArr = result.map(x => renderCoreAsync(x, './src/index.template.html', false))
});
function getBundle(config) { return new Promise((resolve, reject) => { process.env.NODE_ENV = 'production'; child_process.exec('npm run build', function (error, stdout, stderr) { if (error) { console.error('error: ' + error); reject(); } resolve(); }); }); }
function renderCoreAsync(url, templateSrc, pure) { return new Promise((resolve, reject) => { const context = { title: 'Vue HN 2.0', // default title url: url, pure: pure } if(!fs.existsSync(baseUrl)) { fs.mkdirSync(baseUrl); } const template = fs.readFileSync(templateSrc, 'utf-8') delete require.cache['./dist/vue-ssr-server-bundle.json']; const bundle = require('./dist/vue-ssr-server-bundle.json') // The client manifests are optional, but it allows the renderer // to automatically infer preload/prefetch links and directly add Githubissues.