vue-hackernews-2.0 icon indicating copy to clipboard operation
vue-hackernews-2.0 copied to clipboard

使用express生成静态网页,为何页面的js引用不更新呢

Open tjswk2008 opened this issue 6 years ago • 0 comments

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

调用几次generate之后,发现生成的html的js引用并不更新 image

tjswk2008 avatar Oct 12 '18 11:10 tjswk2008