[英]How to webpack a npm module?
我想使用npm模块在浏览器中运行simpleWeather jQuery插件。 听说我需要使用捆绑器,所以我安装了Webpack。
这是文件夹结构:
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>simpleWeather.minimum.js</title>
<style>
</style>
</head>
<body>
<div id="weather"></div>
<script src="js/bundle.js"></script>
</body>
</html>
index.js:
$(document).ready(function() {
$.simpleWeather({
location: 'Austin, TX',
woeid: '',
unit: 'f',
success: function(weather) {
html = '<p>'+weather.temp+'°'+weather.units.temp+'</p>';
$("#weather").html(html);
},
error: function(error) {
$("#weather").html('<p>'+error+'</p>');
}
});
});
webpack.config.js:
module.exports = {
entry: "./js/index.js",
output: {
filename: "js/bundle.js"
}
}
我想这在浏览器中行不通,我需要以某种不同的方式配置Webpack。
我需要做什么?
您需要在index.js中导入节点包依赖项[jquery,simpleweather]并进行webpack构建以生成bundle.js
现在在webpack中加载jQuery有点棘手,因此可以参考以下答案: https ://stackoverflow.com/a/28989476/1681972
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.