I am trying to print dynamic message using webpack 3 and ES6 using babel and hotmodulereplacement()
in webpack but, I cannot print messages. Below is the code. cannot print:
var newMessage = () => ('<p>${messages.hi} ${messages.event}</p>');
messages.js file
module.exports = {
hi: 'Hello there content changed',
event: 'this is new webpack'
};
index.js file
var messages = require('./messages');
var newMessage = () => ('<p>${messages.hi} ${messages.event}</p>');
var app = document.getElementById('app');
app.innerHTML = newMessage();
if(module.hot){
module.hot.accept();
}
index.html file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app"></div>
<script src="dist/bundle.js"></script>
</body>
</html>
Output on webpage:
${messages.hi} ${messages.event}
I suspect you want to use the new template literals: for that you have to enclose the string in backticks
`<p>${messages.hi} ${messages.event}</p>`
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
您需要使用反引号(`)而不是引号(')。
`<p>${messages.hi} ${messages.event}</p>`
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.