index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script type="text/javascript" src="bundle.js"></script>
</body>
</html>
main.js
var img1 = document.createElement("img");
img1.src = require("./01.jpg");
document.body.appendChild(img1);
webpack.config.js
module.exports = {
entry: './main.js',
output: {
filename: 'bundle.js'
},
module: {
loaders: [
{ test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192' },
]
}
};
输出后运行index.html,f12查看发现代码里面是:
<body>
<script type="text/javascript" src="bundle.js"></script>
<img src="[object Object]">
</body>
https://segmentfault.com/q/10...