Webpack uses template engine to introduce packaged js problem in node server

  node.js, question

The webpack has packed out 2 JSs. I want to introduce these 2 JSs into ejs, which are now Hard coding file names.

 <script type="text/javascript" src="/__build__/vendor.js"></script>
 <script type="text/javascript" src="/__build__/app.js?  v=0.11"></script>

What I want is for the webpack to be packaged[name].[hash:8].js, but what should be written in the ejs template above?

The following is another pure front-end project that I can write in this way, but the above project uses background rendering pages. How should it be written?

{percentage for (varchunk in o.htmlwebpackplugin.files.chunks) {percentage}
 < script src="{ percentage = o.htmlwebpackplugin.files.chunks [chunk]. entry percentage }"></script >
 {percent} percent}

The above problem has been solved

Solution: Add HtmlWebpackPlugin Plug-in

new HtmlWebpackPlugin({
 template: './server/views/layout.html',
 filename: 'layout.html',
 inject: 'body',
 chunks: ['vendor', 'app']

However, a new problem has arisen. If you write this way, the html of the development environment will be stored in the memory of inside and nodejs.res.render('layout')I can’t read this compiled html. . . .

You can try to store the template in two directories for use during the development phase.views/src/Directory, official access can be stored atview/dist/Down.

Then webpack configuration is divided into development and formal environment. Only formal environment needs to configure HtmlWebpackPlugin plug-in.